You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Havard <br...@kheldar.apana.org.au> on 1999/06/05 08:47:31 UTC

APR: detached threads?

While working on the OS/2 version of the APR threadproc lib I've come accross
the concept of detached threads which is not something I'm familiar with. Can
someone point out why you'd need to use this?

Also, the APR thread interface assumes that a thread has a return value but
that's not the case in OS/2 (and Win32 if I remember right). Do we make use
of it anywhere?

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


Re: APR: detached threads?

Posted by Ryan Bloom <rb...@raleigh.ibm.com>.
On Sun, 6 Jun 1999, Manoj Kasichainula wrote:

> On Sat, Jun 05, 1999 at 05:12:48PM -0400, Ryan Bloom wrote:
> > If the OS doesn't allow for detached threads, we need to know this,
> > because the current hybrid model relies on detached threads.
> 
> Not any more. The need for joinable threads went away with the new
> graceful restart model.

Exactly.  If the OS does not allow for having a detached thread, we would
need to use joinable threads.  The current implementation relies on NOT
using joinable threads.

Ryan

> 
> It's still a useful feature to provide, though.
> 
> -- 
> Manoj Kasichainula - manojk at io dot com - http://www.io.com/~manojk/
> "We don't consider it a loophole. I would think of it more as a
> vulnerability." - Jon Roberts, Microsoft spokesman
> 

_______________________________________________________________________
Ryan Bloom		rbb@raleigh.ibm.com
4205 S Miami Blvd	
RTP, NC 27709		It's a beautiful sight to see good dancers 
			doing simple steps.  It's a painful sight to
			see beginners doing complicated patterns.	


Re: APR: detached threads?

Posted by Manoj Kasichainula <ma...@io.com>.
On Sat, Jun 05, 1999 at 05:12:48PM -0400, Ryan Bloom wrote:
> If the OS doesn't allow for detached threads, we need to know this,
> because the current hybrid model relies on detached threads.

Not any more. The need for joinable threads went away with the new
graceful restart model.

It's still a useful feature to provide, though.

-- 
Manoj Kasichainula - manojk at io dot com - http://www.io.com/~manojk/
"We don't consider it a loophole. I would think of it more as a
vulnerability." - Jon Roberts, Microsoft spokesman

Re: APR: detached threads?

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
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?
In Win32, yes, by waiting on the thread handles with
WaitForMultipleObjects. You can determine exactly which thread exited.  
> 
> 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.
> 
> Ryan
> 
> _______________________________________________________________________
> Ryan Bloom              rbb@raleigh.ibm.com
> 4205 S Miami Blvd
> RTP, NC 27709           It's a beautiful sight to see good dancers
>                         doing simple steps.  It's a painful sight to
>                         see beginners doing complicated patterns.

-- 
Bill Stoddard
stoddard@raleigh.ibm.com

Re: APR: detached threads?

Posted by Brian Havard <br...@kheldar.apana.org.au>.
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 |
 ------------------------------------------------------------------------------


Re: APR: detached threads?

Posted by Ryan Bloom <rb...@raleigh.ibm.com>.
> 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?

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.

Ryan

_______________________________________________________________________
Ryan Bloom		rbb@raleigh.ibm.com
4205 S Miami Blvd	
RTP, NC 27709		It's a beautiful sight to see good dancers 
			doing simple steps.  It's a painful sight to
			see beginners doing complicated patterns.	


Re: APR: detached threads?

Posted by Brian Havard <br...@kheldar.apana.org.au>.
On Sat, 5 Jun 1999 17:12:48 -0400 (EDT), Ryan Bloom wrote:

>
>> Also, the APR thread interface assumes that a thread has a return value but
>> that's not the case in OS/2 (and Win32 if I remember right). Do we make use
>> of it anywhere?
>
>I suggest always returning APR_SUCCESS when the thread returns.  That will
>just mean that the thread returned becaseu we told it to.  If the OS
>doesn't return a error condition, we shouldn't worry about it.  If the OS
>doesn't allow for detached threads, we need to know this, because the
>current hybrid model relies on detached threads.

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.

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


Re: APR: detached threads?

Posted by Ryan Bloom <rb...@raleigh.ibm.com>.
> Also, the APR thread interface assumes that a thread has a return value but
> that's not the case in OS/2 (and Win32 if I remember right). Do we make use
> of it anywhere?

I suggest always returning APR_SUCCESS when the thread returns.  That will
just mean that the thread returned becaseu we told it to.  If the OS
doesn't return a error condition, we shouldn't worry about it.  If the OS
doesn't allow for detached threads, we need to know this, because the
current hybrid model relies on detached threads.

Ryan
_______________________________________________________________________
Ryan Bloom		rbb@raleigh.ibm.com
4205 S Miami Blvd	
RTP, NC 27709		It's a beautiful sight to see good dancers 
			doing simple steps.  It's a painful sight to
			see beginners doing complicated patterns.