Open martlaak-gmail opened 4 years ago
I stumbled over the same problem, which prevents the upgrade from 1.67 to 1.74 in my case. I can supply a slightly different example, which uses std::async, but in principle it does the same thing as in the original bug report.
This is even worse than the previous issue I had with timed waits with this library... at least that one just made things run slower, as opposed to segfaulting by overflowing the stack.
The issues is noted, I fear I might need to remove those functions altogether though. The only solution that seems to work is to fork a timeout process as it currently does on osx. linux currently uses sigtimedwait which introduced a nasty race condition you're running into.
But even the fork solution seems unreliable (at least on osx) since the timeout might not trigger at all.
I would of course be interested if anyone has ideas on how to implement the timed wait functions, because I can't seem to figure out a portable solution.
I think there are two separate use cases for wait_for here:
The first case could be handled by something like this:
while (c.running())
{
sleep(<short time>);
checkExternalCondition();
}
In this case it does not really matter, if it takes somewhat longer to detect, that the child process has terminated.
However this would not work for the second case. Unfortunately I cannot recommend any solution for this, as I do not have much experience with those more specialized signal handling functions. As my use case is the first one, I will go for a solution based on repeatedly checking, if the subprocess is still running.
Seems POSIX wait_for() is not thread-safe. Following simple program crashes:
With stacktrace:
Notes: