Proper way to code multithreaded applications?

torhu fake at address.dude
Sat Jun 2 04:03:01 PDT 2007


Jason House wrote:
> Sean Kelly wrote:
>> Jason House wrote:
>>> * derr is not synchronized.  Debug output from different threads can 
>>> get multiplexed together.
>> 
>> In my opinion, this is the correct choice from a performance standpoint.
> 
> I may not appreciate the full impact on performance, but I can pretty 
> much guarantee that jumbling the output of two different threads 
> together is rarely what the user wants to see...
> 

I don't think you need more than this to fix that problem:

void debugOutput(char[] msg)
{
     synchronized(derr) {
         derr.writeLine(msg);
         derr.flush();  // might be a good idea  in case of redirection
     }
}


More information about the Digitalmars-d-learn mailing list