Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2002-08-06 16:44:53


Pete Becker wrote:
[...]
> Of course, multi-threaded code that runs threads from constructors is
> inherently evil, so this really shouldn't be much of an issue in practice.

http://www.terekhov.de/mythread.c

"....
 // i think that the following closely matches Java
 // model with respect to thread objects ("automatic"
 // lifetime management of thread objects with
 // optional/multiple/concurrent "join" and creation
 // of initially suspended threads with "start" method
 // to resume initially suspended thread and start
 // execution of user code; call user provided thread
 // start routine)
 // ----
 // i think the later could be useful in C++ library
 // as well, e.g:
 //
 // // User:
 //
 // mutex mtx; // Dynamic init
 // condition cnd; // Dynamic init
 //
 // int f1( int,.... ); // Uses mtx/cnd
 // int f2( int,.... ); // Uses mtx/cnd
 //
 // thread_ref< int,.... > tr1( f1, <parms> ); // Dynamic init; BUT library will enforce suspension
 // thread_ref< int,.... > tr2( f2, <parms> ); // Dynamic init; BUT library will enforce suspension
 //
 // // Library:
 // int main( int argc,char* argv[] )
 // {
 //
 // // Adopt main thread
 // //...
 //
 // // resume threads created (with
 // // suspension enforced) before "main"
 // //...
 //
 // main_thread::main( argc,argv );
 //
 // pthread_exit( NULL );
 //
 // return 0;
 //
 // }
 //
 // // User:
 // void main_thread::main( int argc,char* argv[] )
 // {
 //
 // // ...
 //
 // if ( error )
 // exit( -1 );
 //
 // // return from main_thread::main does *not* invoke
 // // process termination! main_thread::main behaves
 // // just like any other thread function. process
 // // termination occurs ether explicitly (exit/...)
 // // or implicitly on last thread termination.
 //
 // exit( tr1.join() + tr2.join() )
 ...."

regards,
alexander.

P.S. http://www.terekhov.de/thread_ptr.txt ;-) ;-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk