Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^7: Threading in a loop

by BrowserUk (Pope)
on Apr 22, 2013 at 16:15 UTC ( #1029914=note: print w/replies, xml ) Need Help??


in reply to Re^6: Threading in a loop
in thread Threading in a loop

What you are doing makes no sense.

And the way you are doing it makes no sense. This:

while ($test <= 100) { my $thr1 = threads->create(\&progress_count, $test); $test += 1; $thr1->join(); }

Is (unreliably) equivalent to doing this:

while ($test <= 100) { $test += 1; print $test; }

Except that:

  1. it is is vastly more inefficient;

    Because you are building and running and then throwing away a whole new thread in order to execute that single print statement.

    Which is a complete nonsense as it has no advantages and masses of disadvantages.

  2. it is unreliable;

    Because there is no guarantee one way or the other that by the time the thread has been built and the print statement is executed, whether the increment of the variable will have been done or not.

That is, the while loop cannot continue until the print statement (in the thread) has run; so nothing is being "done in parallel".

It doesn't even make sense as a beginners first exploratory step in using threads because it is like trying to test whether a bone china cup can safely contain concentrated sulphuric acid; because regardless of the outcome of the test, nothing useful is being done by doing so.

If you think you have a real application for threading and are stuck on how to do it; describe it and we'll try to help you.

If not, stop playing; because your misunderstanding is such that all you will do is acquire knowledge of how not to use threads.


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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029914]
help
Chatterbox?
[Corion]: Yay! As I had to reset my phone again, I now also back up my SMS automatically. Highly conveniently, there is a program to back up my SMS to my IMAP server as mails ;)
[1nickt]: Corion this is an android phone? If so, are you encountering problems with recent upgrades? Lately my phone dies suddenly quite often, seemingly coredumps caused by interaction of two actions, eg phone playing a sound and user swiping simultaneously :-/
[Corion]: 1nickt: Yeah, it's Android, but it's CM 11, so fairly old. I'm looking for a newer (china) phone, but I think I'll wait until Oreo ROMs get out for them
[Corion]: Otherwise, the Vernee Mars looks tempting
[Corion]: ... but alas, no Oreo support in sight yet, and I prefer to flash a stock Android over the custom ROMs, and Oreo promises to make the userland more maintainable.
[LanX]: Corion: shouldn't pmdev have permission to view code of nodelets?
[1nickt]: And of course everything is "unlocked" in EU, right?
[1nickt]: I think there are far more choices than in the US
LanX You don't have access to  Function Nodelet.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-11-18 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?