Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Thread creation failed: pthread_create returned 11

by BrowserUk (Patriarch)
on Aug 11, 2015 at 00:18 UTC ( [id://1138091]=note: print w/replies, xml ) Need Help??


in reply to Thread creation failed: pthread_create returned 11

If you'd care to provide a runnable program -- that uses strict & warnings and compiles clean -- I'd be willing to take a look at the problem; but I'm not enamored to do so whilst your code contains errors like these:

C:\test>junk77 Global symbol "$message" requires explicit package name at C:\test\jun +k77.pl line 9. Global symbol "$msgQueue" requires explicit package name at C:\test\ju +nk77.pl line 9. Global symbol "$message" requires explicit package name at C:\test\jun +k77.pl line 12. syntax error at C:\test\junk77.pl line 15, near "4)" Global symbol "$message" requires explicit package name at C:\test\jun +k77.pl line 16. Bareword "processData" not allowed while "strict subs" in use at C:\te +st\junk77.pl line 12. Bareword "processData" not allowed while "strict subs" in use at C:\te +st\junk77.pl line 16. Execution of C:\test\junk77.pl aborted due to compilation errors.

Which when I attempt to fix them in the obvious way results in this error:

C:\test>junk77 Can't locate object method "poll" via package "Thread::Queue" at C:\te +st\junk77.pl line 12.

On the basis on what you've posted, I cannot see how you could ever get the error message you cite.


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". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^2: Thread creation failed: pthread_create returned 11
by kamrul (Acolyte) on Aug 11, 2015 at 16:32 UTC
    This should reproduce the problem:
    use threads; use threads::shared; my $tcount :shared = 0; while(1){ if($tcount < 4){ print("Number of active threads : ".$tcount." processing incom +ming message\n"); threads->create(processData); } else { print("Maximum number of threads reached. Waiting \n"); sleep 1 until $tcount < 4; threads->create(processData); } } sub processData { $tcount++; #sleep(2); print "OK \n"; $tcount--; threads->exit(); }

      You are simply exhausting your memory because you are never joining your threads.

      The easiest fix is to just detach your threads so they get cleaned up automatically. (Also, there is no point in calling threads->exit; better to just fall off the end.

      So whilst your example above chews up 8GB of memory in around a minute or so, this slightly modified version runs with no signs of memory growth at all:

      #! perl -sw #use strict; use threads; use threads::shared; my $tcount :shared = 0; while(1){ if($tcount < 4){ print("Number of active threads : ".$tcount." processing incom +ming message\n"); threads->create(processData)->detach; } else { print("Maximum number of threads reached. Waiting \n"); sleep 1 until $tcount < 4; threads->create(processData)->detach; } } sub processData { $tcount++; #sleep(2); print "OK \n"; $tcount--; }

      There are several other bad things and weirdnesses in that short snippet -- most of which would be cured by making it strict/warnings safe; but I guess that request fell on deaf ears -- but it will cure your headline problem.


      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". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-20 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found