Pthread Create Error Code 11
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring how to find pthread_threads_max developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Pthread Error Handling
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them;
Pthread Error Codes To String
it only takes a minute: Sign up Return code from pthread_create() is 11 up vote 2 down vote favorite 2 I am trying to run a simple multi threaded programming and i am getting this error from gcc return code
Error Return Code From Pthread_create Is 11 Error Detail Resource Temporarily Unavailable
from pthread_create() is 11 how do i solve this issue ? #include I agree with asking the next question in the threading group.] >i have a code that uses pthread, but when i use pthread_create() >method it returns error code 11. That would depend on what error 11 is. On my system, errno.h says: #define EDEADLK pthread_create resource temporarily unavailable 11 /* Resource deadlock avoided */ /* 11 was EAGAIN */ So, 11 once was EAGAIN, which pthread_attr_setstacksize is a known return for pthread_create(). It may still be on your implementation. My system's man page says: The pthread_create() function will fail if: [EAGAIN] The man pthread_create system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process [PTHREAD_THREADS_MAX] would be exceeded. >I have found out that this is often >because of exceeding the THREAD_MAX limit for the process. http://stackoverflow.com/questions/7038586/return-code-from-pthread-create-is-11 But i want >to use only about 24 threads at a given time, and i destroy the >threads (or atleast i thought so) can someone tell me what i am doing >wrong here it would be of great help! thanks! My next guess is that your system won't allow a user process to run 24 (additional) threads. But most of what I can say about pthreads is guesses. The experts in comp.programming.threads know this stuff inside and out. -- Drew Lawson Some men's dreams for others http://www.thecodingforums.com/threads/re-pthread_create-returns-error-code-11.685758/ turn to nightmares. I never would have thought this in my wildest dreams. Drew Lawson, May 27, 2009 #1 Advertisements Antoninus Twink Guest On 27 May 2009 at 16:51, Drew Lawson wrote: > Harshith <> writes: >>i have a code that uses pthread, but when i use pthread_create() >>method it returns error code 11. > > That would depend on what error 11 is. On my system, errno.h says: > #define EDEADLK 11 /* Resource deadlock avoided */ > /* 11 was EAGAIN */ > > So, 11 once was EAGAIN, which is a known return for pthread_create(). > It may still be on your implementation. It seems likely that it is, given the code that produced it. Of course, he can find out for sure by passing the return value from pthread_create() to strerror(). Antoninus Twink, May 28, 2009 #2 Advertisements Show Ignored Content Want to reply to this thread or ask your own question? It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum. Sign Up Now! Similar Threads pthread_create for class ? vertigo, Aug 28, 2004, in forum: Java Replies: 4 Views: 1,125 Tor Iver Wilhelmsen Aug 29, 2004 Object Argument passing in pthread_create nightowl, Oct 21, 2004, in forum: C++ Replies: 1 Views: 2,461 Ron Natalie Oct 21, 2004 What is the problem with Pthread_create yezi, Nov 1, 2005, in forum: C Programming Replies: 5 Views: 1,253 Emmanuel Delaha 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 = http://www.perlmonks.org/?node_id=1138090 $msgQueue->poll()){ if($tcount < 4){ Logger::log(3, "Number of active threads : ".$tcount." pro +cessing incomming message"); https://www.parkes.atnf.csiro.au/observing/documentation/computing_notes/linux_threads.html 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 error code 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 how to find 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 be more efficient if I keep 4 running threads and pass the messages to the threads using a queue; rather than creating new threads every time ? [reply] Re: Thread creation failed: pthread_create returned 11 (RTFM) by tye (Sage) in the non-detached mode, and the limited available memory in some system stack is consumed. At that point no new threads can be created in non-detached mode until those threads are 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 (&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 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]