httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Havard" <bri...@kheldar.apana.org.au>
Subject Re: APR: detached threads?
Date Mon, 07 Jun 1999 01:23:58 GMT
On Sun, 6 Jun 1999 17:19:08 -0400 (EDT), Ryan Bloom wrote:

>> Going by Ralf's explanation, OS/2 kernel threads are always detached. If
>> there's a need for threads to be able to pass a return value back to their
>> parents I can implement that in APR with an extra layer.
>> 
>
>I have just started Windows programming, so I only really know Posix
>threads.  If Os/2 (and windows?) threads are always detached, is it
>possible for other threads in the same process to know when a certain
>thread has exited?

Yes, you can wait on a thread in the same way as you can a process. There's
just no return value when you do so. BTW, windows threads are the same as
OS/2's in every way I know about (except that OS/2 is faster :).



>It would be really nice to allow threads to return a value, so that we can
>monitor why the thread has exited.  It is not absolutely necessary right
>away.  If you have other parts of APR that need your attention more
>urgently, I would suggest putting it off.  It won't be used in the first
>apache-hybrid release anyway.  It should be done sometime though.

It's ok, I've done it already. I've used a thread front end function that
looks like this:

static void ap_thread_begin(void *arg)
{
  struct thread_t *thread = (struct thread_t *)arg;
  thread->rv = thread->func(thread->data);
}


So ap_thread_join() waits for the thread to finish then gets the return value
from the thread_t->rv field. This is only used if the thread is started
joinable.

The only potential problem is that the context that created the thread must
live longer than the thread if it's joinable or it will segfault trying to
set the return value. That shouldn't happen though as you need the context to
do the join.

--
 ______________________________________________________________________________
 |  Brian Havard                 |  "He is not the messiah!                   |
 |  brianh@kheldar.apana.org.au  |  He's a very naughty boy!" - Life of Brian |
 ------------------------------------------------------------------------------


Mime
View raw message