On Linux program exit, calling function futex(... FUTEX_WAIT_PRIVATE...) leaves the process hanging

376 Views Asked by At

I have many multithread C++ programs built in Red Hat 2.6.18-164.11.1.el5 and they run and exit properly e.g. in Red Hat 4.18.0-240.15.1.el8_3.x86_64 - no matter if daemonized or not.

But if I build and run them in 4.18.0-372.16.1.el8_6.x86_64, they

  • runs properly,
  • exit properly if not daemonized,
  • but if daemonized, jams on exit after running out of main ( daemonized using function daemon() ).

What might be the reason?

All I have found out is the following:

strace-print if not daemonized:

...
close(4)                                = 0
munmap(0x7f71715f8000, 2105416)         = 0
futex(0x25323b0, FUTEX_WAKE_PRIVATE, 2147483647) = 4
futex(0x2532330, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x2532330, FUTEX_WAKE_PRIVATE, 1) = 0
close(25)                               = 0
...

strace-print if daemonized:

...
close(3)                                = 0
munmap(0x7ff978453000, 2105416)         = 0
futex(0xf953b0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0xf953b4, FUTEX_WAIT_PRIVATE, 0, NULL) = ?
+++ killed by SIGKILL +++
...

So, calling futex with "waking up all waiters":

  • returns 4 if not daemonized, but
  • returns 0 otherwise, and then the next futex-call jams and brutal killing is the only option.

Is this significant or not?

What might it be I'm doing wrong... any idea?

And remember, I do not use futex function - calls are made by the system itself.

-J

P.S.

Daemonizing using fork does not help.

Forking twice leaves the first child hanging - probably for the same, unknown reason.

0

There are 0 best solutions below