httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralf S. Engelschall" <>
Subject Re: APR: detached threads?
Date Sat, 05 Jun 1999 08:44:39 GMT

In article <> you wrote:

> 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?

The detachment and return values are related.  In the POSIX thread model, a
thread is either joinable (default) or detached. When it's joinable and the
thread terminates (it "return <val>;" from its startup routine or calls
"pthread_exit(<val>);") the thread is just marked as terminated but kept in
memory until some other thread joins it. With this the <val> is copied to the
thread who does the join and then the thread is kicked out of the threading

In other words: When you spawn a joinable thread you _HAVE_ to join it or
you'll quickly run out of memory (because each terminated thread usually
consumes memory for its stack, etc.). When you want to avoid these potential
memory leaks and especially don't need a return value from threads, you can
spawn the threads detached. Here you've no chance to join it, of course.  And
when the thread terminated, it's immediately kicked out of the threading

I hope my explanation is correct.
                                       Ralf S. Engelschall

View raw message