Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Cross-platform testers please.

by BrowserUk (Patriarch)
on Apr 27, 2005 at 10:05 UTC ( [id://451884]=note: print w/replies, xml ) Need Help??


in reply to Printing to STDERR causes deadlocks.

Below is a version of the code in the OP that (on my system) works reliably and apparently quite efficiently regardless of tracing, filesize, system load, whatever.

I would be most grateful if people running a multithreaded perl on non-Win platforms, and especially anyone with a multi-cpu machine, could try this code and report back their findings.

#!/usr/bin/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( !$handle->eof ) { warn 't-Waiting' . $/; select undef,undef, undef, 0.0001 while $$sharedDataRef; warn "t-Locking" . $/; lock $$sharedDataRef; warn 't-Setting' . $/; $$sharedDataRef = $handle->getline; } $$doneRef = 1; return; } my $handle = IO::File->new( $ARGV[ 0 ], 'r' ); my $sharedData :shared = undef; my $done :shared = 0; threads->create( \&getDataT, $handle, \$sharedData, \$done ); while( !$done ) { warn 'm-waiting' . $/; select undef, undef, undef, 0.0001 until $sharedData; warn 'm-locking' . $/; lock $sharedData; warn 'm-Copying' . $/; my $localCopy = $sharedData; warn 'm-undefing' . $/; undef( $sharedData ); warn 'm-processing' . $/; processData( $localCopy ); }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?

Replies are listed 'Best First'.
Re: Cross-platform testers please.
by ghenry (Vicar) on Apr 27, 2005 at 10:15 UTC

    Tried it on a Dual 2.8Ghz Xeon 1GB Dell 1800 PE with perl 5.8.3

    Fine with/without tracing on SUSE 9.1

    HTH.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!

      Many thanks. Can you tell if the two threads were running on separate cpus?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco.
      Rule 1 has a caveat! -- Who broke the cabal?

        I don't want to appear stupid, but can you tell me how to check?

        Walking the road to enlightenment... I found a penguin and a camel on the way.....
        Fancy a yourname@perl.me.uk? Just ask!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://451884]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-25 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found