Re: [PATCH 5/4] run-command: implement abort_async for pthreads
- From
Erik Faye-Lund <kusmabite@gmail.com>
- Date
- Apr 1, 2011, 19:57 UTC
- Message-ID
- <AANLkTimKPD6rw1B9gG3ZN0KEOY41nk=6jE0MVcdotpkp@mail.gmail.com>
- In-Reply-To
- <201104012142.22065.j6t@kdbg.org>
On Fri, Apr 1, 2011 at 9:42 PM, Johannes Sixt <j6t@kdbg.org> wrote:
Show 32 quoted lines
> On Freitag, 1. April 2011, Erik Faye-Lund wrote: >> On Fri, Apr 1, 2011 at 7:27 PM, Johannes Sixt <j6t@kdbg.org> wrote: >> > On Freitag, 1. April 2011, Erik Faye-Lund wrote: >> >> OK, I've read up on thread-cancellation, and this code seems correct. >> >> pthread_cancel doesn't kill the thread right away, it just signals a >> >> cancellation-event, which is checked for at certain >> >> cancellation-points. A lot of the CRT functions are defined as >> >> cancellation points, so it'll be a matter for us Win32-guys to >> >> implement pthread_testcancel() and inject that into the >> >> function-wrappers of the CRT functions that are marked as >> >> cancellation-points. >> > >> > That's not going to happen. We cannot implement pthread_cancel() on >> > Windows because it would have to be able to interrupt blocking system >> > calls. (TerminateThread() is a no-no, given all the caveats about leaking >> > system resources that are mentioned in the manual.) >> >> Did you read my suggestion? > > Yes, I did. > >> I was talking about implementing >> cancellation-points, just like on other platforms. This should not >> lead to TerminateThread, but instead a conditional ExitThread from the >> thread in question. >> >> Something like this (I've only added a cancellation-point at close, >> just to illustrate what I mean): > > But this does not help the case at hand in any way. How would you interrupt a > thread that is blocked in ReadFile()? The point of pthread_cancel() is that > it interrupts blocked system calls
There is no mention of such a guarantee in POSIX (section 2.9.5 Thread Cancellation), so relying on that is undefined behavior.