[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trouble joining with threads from C
From: |
Andy Wingo |
Subject: |
Re: Trouble joining with threads from C |
Date: |
Fri, 15 Apr 2011 10:41:42 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Hi Ludovic,
On Wed 13 Apr 2011 23:34, address@hidden (Ludovic Courtès) writes:
> After reviewing f60a7648d5926555c7760364a6fbb7dc0cf60720 (which
> addressed the same issue), I lean towards reverting it and instead
> applying the patch I just sent.
>
> The problem I see with f60a7648d5926555c7760364a6fbb7dc0cf60720 is that
> it re-introduces a pthread_key, even when using TLS, and make things a
> bit complex IMO.
The issue is that threads in Guile are not always spawned by Guile.
It's true that of the two cases in which Guile spawned a thread, one of
them wasn't getting the cleanup handlers called, and your patch fixes
that; but that ignores the case of threads that are spawned by a user's
program.
For example in the following program:
void* thread (void*)
{
scm_with_guile (do_something, NULL);
scm_with_guile (do_something_else, NULL);
return NULL;
}
int main ()
{
pthread_t thr;
pthread_create (&thr, NULL, thread, NULL);
pthread_join (thr, NULL);
return 0;
}
When do you propose that the cleanup handlers for the thread be called?
As far as I understand things, reliably cleaning up after the thread
*requires* the use of pthread_key with a destructor. It is the only way
to attach a cleanup callback to a thread. It's true that the key is not
used when TLS is available, except for its destructor capabilities, but
it is not more complicated than before.
I think they context that you are missing here is bug 32436.
It does appear that I have introduced some bugs here: Mark's
after-gc-hook not being called, and a failure to build
--without-threads. For that I apologize. But these bugs are fixable.
Consider bug 32436 for a moment: you can't fix that with
pthread_cleanup_push.
Does this explanation help?
Let me know,
Andy
--
http://wingolog.org/