in reply to Re^10: [threads] Open a file in one thread and allow others to write to it
in thread [threads] Open a file in one thread and allow others to write to it
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: [threads] Open a file in one thread and allow others to write to it
by gulden (Monk) on Nov 16, 2009 at 19:49 UTC | |
by ikegami (Patriarch) on Nov 16, 2009 at 19:56 UTC |