Pthread Error Code 11
Contents |
von GoogleAnmeldenAusgeblendete FelderNach Gruppen oder Nachrichten suchen
is 8MB. pthread_detach() is important to release thread resource so that it can be reclaimed. I had this program running with 115 threads, and there were many others
Pthread_create Return
dynamically created during runtime. At some point, I noticed these dynamic threads were pthread_create resource temporarily unavailable not created properly, it took me a while to figure out the problem was on pthread_create() which returned error
Pthread_attr_setstacksize
code 11: Resource temporarily unavailable. I searched through the Internet and manuals trying to figure out what is the maximum number of threads supported in a process, and it seemed there https://groups.google.com/d/topic/comp.programming.threads/huD7rhbMQ6c was no hard limit on this. So I decided to run a small test with the follow piece of code. #include
in the non-detached mode, and the limited available memory https://www.parkes.atnf.csiro.au/observing/documentation/computing_notes/linux_threads.html in some system stack is consumed. At that point no new threads can be created in non-detached mode until those threads are http://www.perlmonks.org/index.pl?node_id=1138090 detached/killed, or the parent process(es) killed and restarted. Solution: create the threads in the detached state with the pthread_attr_setdetachstate call, e.g.; pthread_attr_init pthread error (&id_attr); pthread_attr_setdetachstate(&id_attr, PTHREAD_CREATE_DETACHED); pthread_create( , &id_attr, , ); unless you really need the threads in the joinable (non-detached) state, in which case you will have a fixed upper limit to the number of joinable threads active at any one time. In the 2.4 kernels pthread error code I've examined this limit appears to be 256 threads for each parent process(?). Some of this is documented in the man help for pthread_attr_init. However the man help for pthread_create makes no mention of the ENOMEM return and what it means, which is rather confusing. In the Linux 2.2 kernels I've examined the behaviour is slightly different. The system default for the maximum joinable threads alive at any one time seems to be 1024 (rather than 256), and pthread_create returns an error code 11 EAGAIN, and a global errno value of 4 ("Interrupted system call"). The solution is the same as for 2.4: if your process creates lots of threads, make them detached or manage carefully their maximum instantaneous population. John Reynolds December 2004 [an error occurred while processing this directive]
PerlNews Q&A Tutorials Poetry RecentThreads NewestNodes Donate What'sNew on Aug 10, 2015 at 23:49UTC ( #1138090=perlquestion: print w/replies, xml ) Need Help?? kamrul has asked for the wisdom of the Perl Monks concerning the following question: My code is like below: my $tcount :shared = 0; while( $message = $msgQueue->poll()){ if($tcount < 4){ Logger::log(3, "Number of active threads : ".$tcount." pro +cessing incomming message"); threads->create(processData,$message,createMsgId()); } else { Logger::log(2, "Maximum number of threads reached. Waiting +"); sleep 1 until $tcount < 4); threads->create(processData,$message,createMsgId()); } } sub processData { $tcount++; # do something $tcount--; threads->exit(); } [download] As per my understanding I am not creating more than 4 threads at a time. However, after running this script for a while I get: Thread creation failed: pthread_create returned 11 What wrong am I doing?Comment on Thread creation failed: pthread_create returned 11Download Code Replies are listed 'Best First'. Re: Thread creation failed: pthread_create returned 11 (races, leaks) by tye (Sage) on Aug 11, 2015 at 05:11UTC I am not creating more than 4 threads at a time. Actually, you could create unbounded many threads between the call to threads->create() and when that thread finally gets created and runs far enough to execute $tcount++. You could certainly reduce that potential problem by moving the duplicate threads->create() calls out of the if/else blocks so you have just one copy of it below that and do the $tcount++ there instead of inside of processData(). You could still potentially accumulate unbounded many threads whose execution lies somewhere between the $tcount-- and the actual ending of the thread. You also don't appear to ever join() nor detach() any of these threads. That surely builds up a growing stash of information about what each thread "returned", much like a memory leak. These types of problems are part of why the usual pattern is to just create 4 threads and then farm out items to them to execute (usually using a thread queue). - tye [reply][d/l][select] Re^2: Thread creation failed: pthread_create returned 11 (races, leaks) by kamrul (Acolyte) on Aug 11, 2015 at 16:39UTC Based on what you said, it seems those threads take a bit of time to get created. In that case, will it