resume a calling thread
Sean Kelly
sean at f4.ca
Tue Jun 6 13:18:29 PDT 2006
pause and resume are really intended for use by the garbage collector
and shouldn't really be called in user code, as pausing a thread that's
executing a system call or holding a lock can cause other threads to
hang waiting for that resource. I'm not sure how well it applies to
Phobos, but Ares has a ThreadGroup class specifically for what you're
trying to do. Use is simple:
void main() {
void run() {
printf( "running\n" );
Thread.sleep( 10000 );
printf( "done\n" );
}
ThreadGroup g = new ThreadGroup;
g.create( &run );
g.create( &run );
g.joinAll( false );
}
The 'false' paramater to joinAll removes thread references when they
have completed, allowing the objects to be collected by the GC.
Currently, this works via foreach and Walter has said that altering a
data structure during foreach is technically illegal, but I haven't
found the time to develop a workaround. In any case, it works just fine
at the moment.
Sean
More information about the Digitalmars-d
mailing list