[fpc-pascal] TThread.Suspend under Linux
Jonas Maebe
jonas.maebe at elis.ugent.be
Sat Jun 2 12:35:25 CEST 2007
On 02 Jun 2007, at 10:10, Graeme Geldenhuys wrote:
> The GUI in frozen after that. Unresponsive, doesn't repaint, etc... I
> have to kill it with 'xkill' and click on the form.
No, you can also type "fg" to let the process continue.
> But as soon as I
> Suspend a thread, it returns me to the prompt! Why???
Because sending pthread_kill(SIGSTOP) to a particular thread
apparently has to freeze the entire the process on posix-compliant
systems, and not just the target thread. Early Linuxthreads
implementations did not implement this properly and only stopped the
targeted thread, but this has been fixed in NPTL.
There is no portable way to suspend a thread at an arbitrary point
under *nix, see
http://pauillac.inria.fr/~xleroy/linuxthreads/faq.html#E
(question E.4)
And the reason for that is probably the other thing that's mentioned
there:
"Notice that thr_suspend() is inherently dangerous and prone to race
conditions. For one thing, there is no control on where the target
thread stops: it can very well be stopped in the middle of a critical
section, while holding mutexes. Also, there is no guarantee on when
the target thread will actually stop. For these reasons, you'd be
much better off using mutexes and conditions instead. The only
situations that really require the ability to suspend a thread are
debuggers and some kind of garbage collectors."
Of course, since Windows provides such functionality, people
nevertheless depend on this. But when creating cross-platform code,
it's clearly a very bad idea (and several of the caveats mentioned
above can of course also hold true under Windows).
I will remove the pthread_kill(SIGSTOP) from the RTL, since it
obviously does not do what people expect it to do.
Jonas
More information about the fpc-pascal
mailing list