Pthread_create Failed With Error 11
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have how to find pthread_threads_max Meta Discuss the workings and policies of this site About Us pthread error handling Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with pthread error codes to string us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just
Error Return Code From Pthread_create Is 11 Error Detail Resource Temporarily Unavailable
like you, helping each other. Join them; 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 from pthread_create() is 11 how do i solve this issue how to find pthread_threads_max ubuntu ? #include Reviews CoolUsesForPerl 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 pthread_create return = 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 http://stackoverflow.com/questions/7038586/return-code-from-pthread-create-is-11 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 http://www.perlmonks.org/?node_id=1138090 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 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: 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 http://unix.stackexchange.com/questions/253903/creating-threads-fails-with-resource-temporarily-unavailable-with-4-3-kernel Us Learn more about Stack Overflow the company Business Learn more about hiring developers https://www.varnish-cache.org/trac/ticket/572 or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a how to question Anybody can answer The best answers are voted up and rise to the top Creating threads fails with “Resource temporarily unavailable” with 4.3 kernel up vote 13 down vote favorite 5 I am running a docker server on Arch Linux (kernel 4.3.3-2) with several containers. Since my last reboot, both the docker server and random programs within the containers crash with a message about not being able to how to find create a thread, or (less often) to fork. The specific error message is different depending on the program, but most of them seem to mention the specific error Resource temporarily unavailable. See at the end of this post for some example error messages. Now there are plenty of people who have had this error message, and plenty of responses to them. What’s really frustrating is that everyone seems to be speculating how the issue could be resolved, but no one seems to point out how to identify which of the many possible causes for the problem is present. I have collected these 5 possible causes for the error and how to verify that they are not present on my system: There is a system-wide limit on the number of threads configured in /proc/sys/kernel/threads-max (source). In my case this is set to 60613. Every thread takes some space in the stack. The stack size limit is configured using ulimit -s (source). The limit for my shell used to be 8192, but I have increased it by putting * soft stack 32768 into /etc/security/limits.conf, so it ulimit -s now returns 32768. I have also increased it for the docker process by putting LimitSTACK=33554432 into /etc/systemd/system/docker.servi Resource temporarily unavailable (Thread Problem on Linux) Reported by: whocares Owned by: phk Priority: normal Milestone: Component: varnishd Version: trunk Severity: normal Keywords: Cc: Description Today I tried kristian's Performance tips on a Linux box and ran into the same problem as was already mentioned in #85: Depending on what box I tried, I never managed to get more than 238 to 302 threads. The reason for that behaviour is that on Linux the number of threads that can be started is essentially limited by the stack size occupied by every thread. In a standard configuration every thread will get 8 MByte of stack attached to it. Thus, in conjunction with other memory related limits in a standard Linux environment you'll never ever get more than around 240 to 300 threads. You can however modify the thread's stack size before creating the thread by doing something like this: include "bits/local_lim.h" pthread_attr_t attr; pthread_t thread[1024*1024]; size_t size; /* do some calculation for optimal stack size or ... */ size = PTHREAD_STACK_MIN; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, size); pthread_create(&thread[somecounter], &attr, (void *)&function_to_run, NULL); ... On Linux this will set the stack size to 16384 bytes which of course is way too small, but allows for around 32.000 threads to be created on my test box. If you like to rum some tests for yourself I attach a sample C program to test different thread stack sizes on a Linux box. It's possible that the code will run on other platforms, too, but I didn't test that. Anyway, it would be nice if varnish would set it's thread's stack size to a reasonable value so that poor Linux users can enjoy at least some of the performance that is possible on FreeBSD and Solaris ;) Attachments thread-limit.c (1.5 KB) - added by whocares 2009-11-01T15:27:09+01:00 ago. Tests the number of threads that can be started with varying stack sizes varnish-stack.patch (2Pthread_create Resource Temporarily Unavailable
Pthread_attr_setstacksize