Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Thread creation failed: pthread_create returned 11 (Either join or detach)

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


in reply to Re^2: Thread creation failed: pthread_create returned 11
in thread Thread creation failed: pthread_create returned 11

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!
  • Comment on Re^3: Thread creation failed: pthread_create returned 11 (Either join or detach)
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-24 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found