Concurrency: Java ".join()" equivalent?
Charles McAnany
mcanance at rose-hulman.edu
Mon May 9 08:01:23 PDT 2011
Hi, all. I'm loving message passing! It's so... elegant!
Anyways, I'm doing something like
main(){
spawn(&foo,thisTid())
spawn(&bar,thisTid())
//Do stuff
receive( (bizarreType t) {}); // join with the spawned thread.
//Do stuff dependend on foo() finishing.
receive( (strangeType t) {});
//Bar is now finished, too.
}
void foo(Tid parent){
//Do stuff.
parent.send(new bizarreType());
}
void bar(Tid parent){
//Do stuff.
parent.send(new strangeType());
}
This would be more elegant with something to the effect of:
main(){
Tid fooThread = spawn(&foo);
Tid barThread = spawn(&bar);
//Do stuff.
fooThread.waitForThreadToFinish();
//Do stuff dependend on foo() finishing.
barThread.waitForThreadToFinish();
}
void foo(){
//Do stuff.
}
void bar(){
//Do stuff.
}
Java has this functionality in the .join() method, but I'm not sure how to do
this elegantly in D.
Any ideas?
Thanks,
CEM
More information about the Digitalmars-d-learn
mailing list