in reply to Re^3: Printing to STDERR causes deadlocks.
in thread Printing to STDERR causes deadlocks.
It still hangs when tracing is enabled, except now it hangs every time (20 attempts). I've posted the modified code below in case I screwed something up? (I assumed the my $temp; was an artifact?)
#! perl -slw use strict; use IO::File; use threads; use threads::shared; BEGIN { $| = 1; our $TRACE ||= 0; print "TRACE=$TRACE"; *CORE::GLOBAL::warn = sub {} unless $TRACE; } sub processData { printf @_; } sub getDataT { my ( $handle, $sharedDataRef, $doneRef ) = @_; while( !$$doneRef ) { warn "t-Locking" . $/; lock $$sharedDataRef; warn 't-Waiting' . $/; cond_wait( $$sharedDataRef ) while $$sharedDataRef; warn 't-Setting' . $/; $$sharedDataRef = $handle->getline; # set $done before handing the data over to the main thread $$doneRef = 1 if $handle->eof; warn 't-Signalling' . $/; cond_signal( $$sharedDataRef ); } return; } my $handle = IO::File->new( $ARGV[ 0 ], 'r' ); my $sharedData :shared; my $done :shared = 0; threads->create( \&getDataT, $handle, \$sharedData, \$done ); while( !$done ) { warn 'm-locking' . $/; lock $sharedData; warn 'm-waiting' . $/; cond_wait $sharedData until $sharedData || $done; warn 'm-Copying' . $/; my $localCopy = $sharedData; warn 'm-undefing' . $/; undef( $sharedData ); warn 'm-signalling' . $/; cond_signal $sharedData; warn 'm-processing' . $/; processData( $localCopy ); }
I'd tried several variations on this theme also without success.
I've also tried using locking directly on $done and $$doneRef, more out of desperation than logic, but it made no difference.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Printing to STDERR causes deadlocks.
by bmann (Priest) on Apr 27, 2005 at 01:50 UTC | |
by BrowserUk (Patriarch) on Apr 27, 2005 at 17:28 UTC | |
Re^5: Printing to STDERR causes deadlocks.
by bluto (Curate) on Apr 27, 2005 at 00:12 UTC | |
by BrowserUk (Patriarch) on Apr 27, 2005 at 00:23 UTC |