Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: How can perl thread exit elegantly

by BrowserUk (Pope)
on Apr 23, 2013 at 08:03 UTC ( #1030065=note: print w/replies, xml ) Need Help??

in reply to Re^2: How can perl thread exit elegantly
in thread How can perl thread exit elegantly

Can we define signal of our own?

No. Signals and threading do not mix; and as you've found out, even the "threads signals" apparently intended for use with threads don't work for any reasonable definition of the term.

For example, With SAFE_SIGNALS in force, a signal, even a kill, will not interrupt a join. (That's the first problem with the code you posted in your new thread.)

And even if you worked your way around that; you'll end up having to poll in your threads and that's a nonsense.

Far simpler to set a shared variable true in your main thread signal handler and have your threads poll on that.

But simpler even than that is to just detach your threads -- either when you create them or when you receive the kill signal -- and then exit your main thread. The kids will then just go away silently without any polling or other special considerations, regardless of what they are doing at the time.

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.
  • Comment on Re^3: How can perl thread exit elegantly

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030065]
[Lady_Aleena]: File::Find doesn't have a simple sub wanted example, like get the name of the file.
[Discipulus]: there is also find2perl with your perl installation
[Discipulus]: and in the wanted sub you just calculate the duretion and add it the total, stop
[shmem]: sub wanted { push @files, $File::Find::name if $File::Find::name =~/\.mp3$/ }

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2017-04-23 20:48 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.