hi henry,

here is code i use when i'm running multiple processes, each of which wants to append to the same file. basically, it opens the file with read/write/create ... and if that succeeds, then it asks for an exclusive lock on the file ... and if that succeeds, then it writes.

--sk

stuart kendrick
fhcrc


#!perl

use strict;
use warnings;
use Fcntl qw(:DEFAULT :flock);

our $log = "logfile";
our $msg = "sample text";

# Open files
sysopen(LOG, "$log", O_RDWR | O_CREAT)
  or die "Can't open $log: $!";
flock (LOG, LOCK_EX)
  or die "Can't write-lock $log: $!";

# Move to the end of the file
seek LOG, 0, 2;

# Add the line
print LOG "$msg";

# Close files
close LOG
  or warn "Can't close $log: $!\n";



On Tue, 17 Aug 2004, henry isham wrote:

Hi all,

I have a script with multiple subs that are independent of each other and can run 
simultaneously. So, I'm thinking of threading them. However, each sub writes output to 
the same file. Now, they run sequentially, so that isn't a problem. What 
considerations should I keep in mind when threading these subs? Should I just have 
them output to separate text files and then consolidate those files before my parsing 
starts? Or is there a way to have all the threads write to the same file without 
stepping on each other's output?

Thanks in advance for any and all help.

-Henry





_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to