Weird std.stdio threading bug?
dsimcha
dsimcha at yahoo.com
Mon Apr 27 15:53:04 PDT 2009
The following small test program seems to have a weird deadlock or something:
It should keep printing the phrase "Doing stuff." forever, but it only gets
through maybe two iterations before its CPU usage does to zero and it stops
printing, at least on my computer. Has anyone noticed any bad behavior with
std.stdio and multithreading?
import core.thread, std.stdio;
void main() {
Thread[] myThreads;
foreach(i; 0..4) {
myThreads ~= new Thread( { doStuff(); });
myThreads[$ - 1].start;
}
}
void doStuff() {
while(true) {
synchronized {
writeln("Doing stuff.");
}
}
}
If the writeln line is commented out, this thing keeps executing the empty
loop with measurable CPU usage.
More information about the Digitalmars-d
mailing list