[Gc] Re: pthread_cancel(3) confuses 'GC_suspend_all ()'
hans.boehm at hp.com
Wed Sep 16 15:18:08 PDT 2009
Here's an attempt at a patch. Tested superficially on Linux (Itanium and ARM) and MacOS with today's CVS. (I seem to run into unrelated build problems on Cygwin, but that may be my ancient Cygwin installation.)
Could you confirm that this solves the original problem?
Assuming it does, my inclination would be to check it in. There is some down side risk. Especially with assertions enabled, it may introduce new failures, though they should be near trivial to track down. Having no story at all about cancellation is probably worse.
This patch tries to disable cancellation in a few relatively high level routines, and then (with assertions enabled) checks in the low level routines that it actually was disabled. Thus I think the performance cost with assertions disabled is usually minimal. Writing to the log file probably gets measurably, but not substantially, slower, since GC_printf/GC_write is called from all over the place, and thus needs to explicitly disable cancellation.
We do need additional work on the normal/fast allocation path or in the mark loop or the like.
We currently do assertion checking for cancellation only on platforms on which we believe __thread works, which is currently mostly Linux. This could probably be refined. But so long as we check on one common platform, we should catch most of the problems. And this mechanism has already caught a few.
* include/private/gcconfig.h (CANCEL_SAFE, IF_CANCEL): new macros.
* include/private/gc_priv.h (DISABLE_CANCEL, RESTORE_CANCEL,
ASSERT_CANCEL_DISABLED): New macros.
* alloc.c (GC_maybe_gc): Assert cancellation disabled.
* misc.c (cancel_disable_count): declare.
(GC_init, GC_write): Disable cancellation.
(GC_init): Remove redundant GC_is_initialized test.
* os_dep.c (GC_repeat_read): Assert cancellation disabled.
(GC_get_stack_base): Disable cancellation.
* pthread_stop_world.c (GC_suspend_handler_inner): Disable
* pthread_support.c (GC_mark_thread): Permanently disable
(GC_wait_for_gc_completion, GC_wait_builder, GC_wait_marker):
Assert cancellation disabled.
(fork handling): Disable cancellation, fix comment.
(GC_unregister_my_thread): Disable cancellation.
> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com
> [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of Ludovic Courtès
> Sent: Tuesday, September 15, 2009 12:25 AM
> To: gc at napali.hpl.hp.com
> Subject: [Gc] Re: pthread_cancel(3) confuses 'GC_suspend_all ()'
> Thanks for the quick reply and detailed analysis!
> "Boehm, Hans" <hans.boehm at hp.com> writes:
> > Thus I'd be inclined to go ahead and disable cancellation
> across all
> > potential cancellation points we can find, including the one in the
> > handler, documenting that one as potentially not completely
> > We should also add the warning that Posix asynchronous cancellation
> > should never be used with the collector (or, in my opinion, without
> > it).
> It makes sense to me. Glibc's pthread_setcancelstate(3)
> shouldn't introduce much overhead, so that's probably OK.
> Any idea how many cancellation points lie in libgc code that
> holds the allocation lock?
> Gc mailing list
> Gc at linux.hpl.hp.com
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 14764 bytes
Url : http://napali.hpl.hp.com/pipermail/gc/attachments/20090916/eb7eae49/cancel-0001.obj
More information about the Gc