Pthread_create Error Enomem
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 developers or posting ads with 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 like you, helping each other. Join them; it only takes a minute: Sign up pthread_create fails w/ ENOMEM? up vote 0 down vote favorite I am seeing pthread_create() fail with rc=12 (ENOMEM), on a 64-bit RHEL machine with 4GB of real memory. The 'top' command shows the process is using 1G of virtual memory when thread creation fails. I am able to create 16 joinable threads, but the 17th and subsequent calls fail with the ENOMEM error (which apparently means memory -or- some other resource is unavailable). Any thoughts on what's going wrong? c multithreading pthreads share|improve this question asked Aug 27 '10 at 0:38 Lance Purple 263 3 Really hard to say. It should be able to create more threads than that, especially on a 64-bit machine (is your program compiled with 64-bit pointers, though?) where address space fragmentation should be a non-issue. Could you strace -f the program and post an excerpt (a couple dozen lines before and after the system call, whatever it was, that actually returned ENOMEM should suffice), please? –zwol Aug 27 '10 at 0:42 Could be stack size. Are you explicitly setting it when you create the threads? –Dennis Miller Aug 27 '10 at 1:05 No, I am using the default stack size (ulimit -s says 10240k) code pthread_attr_t threadAttr; pthread_t threadID; pthread_attr_init(&threadAttr); pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_JOINABLE); pthread_attr_setscope(&threadAttr, PTHREAD_SCOPE_SYSTEM); int rc = pthrea
[x] Bug386 - pthread_create returns ENOMEM but should return EAGAIN Summary: pthread_create returns ENOMEM but should return EAGAIN Status: RESOLVED FIXED Alias: None Product: glibc Classification: Unclassified Component: nptl (show other bugs) Version: unspecified Importance: P3 minor Target Milestone: --- Assignee: Ulrich Drepper URL: Keywords: Depends on: Blocks: Reported: 2004-09-15 16:33 UTC by Sebastien Decugis Modified: 2014-05-28 19:44 UTC (History) CC List: 2 users (show) glibc-bugs jhaberman See Also: Host: Target: Build: Last reconfirmed: Attachments test case (274 bytes, text/plain) 2008-07-03 http://stackoverflow.com/questions/3580571/pthread-create-fails-w-enomem 13:53 UTC, Halesh S Details patch to fix the issue (443 bytes, patch) 2008-07-03 13:53 UTC, Halesh S Details | Diff View All Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Sebastien Decugis 2004-09-15 16:33:38 UTC The POSIX standard explicitly requires the function to https://sourceware.org/bugzilla/show_bug.cgi?id=386 return EAGAIN if the system lacks a resource to create the new thread. But when the function lacks memory, the returned error code is ENOMEM. Comment 1 Ulrich Drepper 2004-09-26 12:13:16 UTC I don't think there is any case left where ENOMEM is returned. If yes, provide a test case. Comment 2 Matthew Montgomery 2007-03-29 21:11:08 UTC Hello, If you set ulimit -s 512000 (thread_stack) on a 32bit system with >2GB RAM it is possible to get pthread_create to return ENOMEM. Strangely, ulimit -s unlimited or ulimit -s 8192 does not produce this ENOMEM result. Does pthread_create allocate a whole thread_stack size buffer for each thread if a ulimit -s is defined? See: http://bugs.mysql.com/bug.php?id=27487 OS error code 12: Cannot allocate memory InnoDB: Error: pthread_create returned 12 070329 14:54:41 mysqld ended This behavior has been experienced on: RHEL3 (2.4.21-37.ELsmp) and SuSE 10.1 (2.6.16.13-4-default) glibc-2.4-31 Comment 3 Anton Ghiugan 2007-06-13 20:37:42 UTC Oddly enough, it is more convenient to return the actual error code rather than generic EAGAIN (which would leave programmers blind ...). I would rather say to revise POSIX standard.... Com
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 https://bugzilla.redhat.com/show_bug.cgi?id=1068741 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 pthread_create 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_create error enomem 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]
Printing -XML -Clone This Bug -Last Comment First Last Prev Next This bug is not in your last search results. Bug1068741 - [abrt] pthread_create() fails with EAGAIN Summary: [abrt] pthread_create() fails with EAGAIN Status: CLOSED DUPLICATE of bug 1011179 Aliases: None Product: Fedora Classification: Fedora Component: glibc (Show other bugs) Sub Component: --- Version: 20 Hardware: x86_64 Unspecified Priority unspecified Severity unspecified TargetMilestone: --- TargetRelease: --- Assigned To: Carlos O'Donell QA Contact: Fedora Extras Quality Assurance Docs Contact: URL: https://retrace.fedoraproject.org/faf... Whiteboard: abrt_hash:67fc22140d31acf43a7a52dcbaf... Keywords: Duplicates: 1068748 1068755 1068768 1068957 1071300 1071561 1072085 1073553 1076179 (view as bug list) Depends On: Blocks: Show dependency tree /graph Reported: 2014-02-21 14:31 EST by Brian J. Murrell Modified: 2014-03-14 03:22 EDT (History) CC List: 10 users (show) brian.murrell codonell fabiano jakub law mbarnes mcrha mjs pfrankli spoyarek See Also: Fixed In Version: Doc Type: Bug Fix Doc Text: Story Points: --- Clone Of: Environment: Last Closed: 2014-03-03 13:54:31 EST Type: --- Regression: ---