www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - writefx and threads

reply Matthias Walter <walter mail.math.uni-magdeburg.de> writes:
Hello,

I've written a simple threaded application, where 30 threads only print some
messages. If I use writefln() for this, it looks like this:

...
Thread started...
Thread finished.
TTThread started...
Thread finished.
hread started...
Thread finished.
hread started...
Thread finished.
...

If I use standard printf(), this doesn't happen, it looks like

...
Thread started...
Thread finished...
Thread started...
Thread finished...
...

Looking at std/stdio.d, there's a "__fp_lock(fp);" call in writefx(), but it
seems to me, this doesn't help to sync the output routines. Or are output
routines not supposed to be synced by default? If yes, this seems to be okay
from some point of view, but is somehow irritating!

btw, I'm using dmd-1.00 on Linux.

thank you
Matthias Walter
Jan 24 2007
parent =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
Matthias Walter wrote:
 Hello,
 
 I've written a simple threaded application, where 30 threads only print some
messages. If I use writefln() for this, it looks like this:
 
 ...
 Thread started...
 Thread finished.
 TTThread started...
 Thread finished.
 hread started...
 Thread finished.
 hread started...
 Thread finished.
 ...
 
 If I use standard printf(), this doesn't happen, it looks like
 
 ...
 Thread started...
 Thread finished...
 Thread started...
 Thread finished...
 ...
 
 Looking at std/stdio.d, there's a "__fp_lock(fp);" call in writefx(), but it
seems to me,
 this doesn't help to sync the output routines. Or are output routines not
 supposed to be synced by default? If yes, this seems to be okay from
some point of view,
 but is somehow irritating!
D uses buffered I/O. You may need to explicitly call flush() to finish all output before sending new. One other thing, without thread synchronization there is no guarantee that the threads are run in a specific order. BTW, please use this newsgroup for reporting bugs, there's digitalmars.D.learn for asking questions.
Jan 25 2007