Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Concurrent execution of threads

by kcott (Abbot)
on Nov 29, 2012 at 06:46 UTC ( #1006171=note: print w/ replies, xml ) Need Help??


in reply to Concurrent execution of threads

G'day pplshlp,

// introduces a comment in a number of languages but not in Perl. You need a # in Perl.

With your code, I get:

Bareword found where operator expected at -e line 20, near "//do somet +hing" (Missing operator before something?) syntax error at -e line 21, near "//do something "

Changing //do something to #do something, I get:

Starting main program End of main program

I don't see a concurrency issue:

$ perl -e ' use strict; use warnings; use threads; use threads::shared; print "Started at: ", time, "\n"; print "Starting main program\n"; my @threads; for ( my $count = 1; $count <= 10;$count++) { my $t = threads->new(\&sub1); push(@threads,$t); } foreach (@threads) { $_->join; } print "End of main program\n"; print "Stopped at: ", time, "\n"; sub sub1 { print "Called at: ", time, "\n"; sleep 2; #do something } ' Started at: 1354171101 Starting main program Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 Called at: 1354171101 End of main program Stopped at: 1354171103

-- Ken


Comment on Re: Concurrent execution of threads
Select or Download Code
Replies are listed 'Best First'.
Re^2: Concurrent execution of threads
by pplshlp (Initiate) on Nov 29, 2012 at 09:29 UTC
    Thank you

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-07-08 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls