Thread (39 messages) flat view 39 messages, 3 authors, 2016-06-15

Re: [PATCH 5/4] run-command: implement abort_async for pthreads

From: Jeff King <hidden>
Date: 2016-06-15 22:50:57

On Fri, Apr 01, 2011 at 07:27:03PM +0200, Johannes Sixt wrote:
quoted
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.)

[OK, "cannot" is a hard word. It is possible in some way, I'm sure. But that 
would mean that we implement the equivalent of Cygwin or so...]

But if I understand correctly what Jeff wrote so far, then the pthreaded case 
happens to work - by chance or by design, we don't know (yet). Perhaps we can 
get away with

-	/* no clue */
+	/* pthread_cancel(async->tid); not necessary */
Yeah, I think that would probably work, but I haven't had a chance yet
to look deeper into why the pthread case doesn't hang.

I have another case, too, which is that killing a "git push" in progress
via signal will leave crufty child-processes around, still trying to
push.  One of these is the pack-objects sub-process, and the other is
(in the no-pthreads case) the sideband demuxer.

And obviously fixing that involves aborting the async process, too[1].
But we can again get away without pthread_cancel, because in the pthread
case, we can just rely on the parent process dying to take down the
thread.

-Peff

[1] Actually, my plan is to set up a signal/atexit handler to kill off
children.  Run-command callers can specify an option for "yes, this
child should be killed if I am killed". Async callers will have it
turned on automatically (since they won't even know if it's a subthread
or a different process).  So we won't actually be calling abort_async()
anyway.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help