There's no race condition there. Notice the timestamps aren't in order? You never ask Perl to write to disk, so it writes in 4k chunks, whether the chunk ends in the middle of a line or not.
Simplest solution: Change
toopen LOG, '>', 'log.txt' or die $!;
use IO::Handle qw( ); open LOG, '>', 'log.txt' or die $!; LOG->autoflush(1);
If you're still having jumbled output after fixing the above problem, there might be a problem keeping file pointers in sync. Use the following before the print:
use Fcntl qw( :seek ); seek(LOG, 0, SEEK_END);
I don't think it'll come to that, though.
In reply to Re^11: [threads] Open a file in one thread and allow others to write to it
by ikegami
in thread [threads] Open a file in one thread and allow others to write to it
by Gangabass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |