Proper way to code multithreaded applications?

Jason House jason.james.house at gmail.com
Thu May 31 19:52:47 PDT 2007


I've started writing a multithreaded application and I'm slowly hitting 
into different annoyances.  I'm curious if anyone knows the proper way 
to handle some of these issues.

* must call start to run a thread but thread execution starts with run 
(If that confuses, which it was intended to do.  Make your own run 
method for what you want the thread to do but call the start function 
when you want the thread to begin)
* wait can't be used inside a thread to wait for itself
* yield has no specific timing constraints
* derr is not synchronized.  Debug output from different threads can get 
multiplexed together.
* msleep isn't available on all platforms (problem inherited from C)
* usleep isn't thread safe (problem inherited from C)

My big issue at the moment is how to cause a thread to delay 
(approximately) for a period of time that I specify.  I guess I might be 
ok with yield when the application is in full swing, but I really hate 
for nearly idle threads to peg the CPU when there's nothing to do.


More information about the Digitalmars-d-learn mailing list