in reply to Re^3: Perl5.8.4 , threads - Killing the "async" kid
in thread Perl5.8.4 , threads - Killing the "async" kid

If you are sharing these file handles between threads, then you should be synchronising access to them anyway. Ie. declare a shared variable for use as a mutex, take a lock() on them before printing to them and release it afterward.

Something like this where the logging file is declared before the threads are started?

#!/usr/bin/perl use threads; use threads::shared; my $loglock :shared ; open(LOG, ">/usr/local/lease.log"); sub ilog{ my $text = shift; lock $loglock; print LOG $text; } ## Start defining threads from here on

From your post, this is what I gathered. This should work when multiple threads write to the log file and when one has a lock on the variable, the others cannot write until the lock goes out of scope.

Replies are listed 'Best First'.
Re^5: Perl5.8.4 , threads - Killing the "async" kid
by BrowserUk (Patriarch) on Oct 13, 2010 at 15:27 UTC

    Indeed. That should work fine. (Though you should be checking the open for errors.)

      Thanks. Is there any way I can express my depth of gratitude here?

        You just did.