Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^4: threads, file handles and wxPerl

by sdetweil (Sexton)
on Feb 13, 2013 at 17:27 UTC ( #1018585=note: print w/replies, xml ) Need Help??

in reply to Re^3: threads, file handles and wxPerl
in thread threads, file handles and wxPerl

thank you. I added close $fh; after the write in the event handler. I am letting the thread ending close the open3() created handles cause they were declared as local(). Should I do that explicitly? (adding it didn't cause any issues);

Replies are listed 'Best First'.
Re^5: threads, file handles and wxPerl
by BrowserUk (Pope) on Feb 13, 2013 at 18:58 UTC
    Should I do that explicitly?

    No. Implicit closing works fine. Where the issue arises is typified by this TCP server constuction:

    sub clientHandler { my( $fileno ) = shift; open my $client, ">&=$fileno" or die $!; while( <$client> ) { ...; } } while( my $client = $svr->accept ) { threads->create( \&clientHandler, fileno( $client ) ); }

    The problem is that will work much of the time, especially when testing under light loads, because the thread will succeed in running to the point when the client handle is duped, before the thread that spawned it reaches the end of the while loop and the original $client is auto-closed.

    But then when the program is used under moderately heavy loads, the spawning thread gets another timeslice before the spawned thread has chance to perform the dup, and by the time it does, the handle has been auto-closed and there is nothing to dup.

    It becomes necessary to add a semaphore to prevent the parent thread from reaching the end of the while loop before the child has duped the handle. Not especially difficult; but there are many ways to do it wrongly.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018585]
[Corion]: marto: Well, I think they go a tour every two years and I think it's hard to even get a connection with the crowd at a 20k people concert... But maybe after this time I'll stop too ;)
[Corion]: I still have to see the Pet Shop Boys live before they stop touring at all
[marto]: yeah, I think that as a group creatively they're done. I can understand how it'd be hard to stop the process, album/tour, album/tour, if that's pretty much all you've ever done :)
[marto]: Corion yes I saw them Pandemonium_Tour
[Corion]: marto: Yeah, and I doubt that they'll ever get back to something like Violator/Songs of Faith and Devotion - it would either alienate their "regular" crowd, or be "too much Violator" ;)
LanX needs to see Freddy Mercury'
[Corion]: marto: Yeah, I have that on DVD even, and I missed them last year because I was in London at the time ironically ;)
[marto]: put me in the mood to listen to this now :)
[Corion]: LanX: Well, grab a shovel :)
[Corion]: Kraftwerk also are still touring (well, only Ralf Hütter and Florian Schneider), but I'm too tight fisted to spend EUR 150+ for standing around two hours ;)

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2017-03-24 11:47 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (301 votes). Check out past polls.