public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN
@ 2007-11-02 3:43 wangf at cn dot fujitsu dot com
2007-11-02 3:47 ` [Bug nptl/5245] " wangf at cn dot fujitsu dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: wangf at cn dot fujitsu dot com @ 2007-11-02 3:43 UTC (permalink / raw)
To: glibc-bugs
I found a bug about the return value of pthread_create. The posix expects
EAGAIN for lack of memory, but in fact, it returns ENOMEM.
This problem can be reproduced by the following code:
--------------------------------------------------------------------
#include <stdio.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
void use_up_memory(void)
{
char *c;
int PAGESIZE = getpagesize();
while (1) {
c = mmap(NULL, PAGESIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (c == MAP_FAILED)
break;
}
printf("errno %d: %s\n", errno, strerror(errno));
}
void child()
{
sleep(1);
}
int main(int argc, char *argv[])
{
int err;
pthread_t tid;
use_up_memory();
err = pthread_create(&tid, NULL, (void *)child, NULL);
if (err) {
printf("pthread_cretate returns %d: %s\n", err, strerror(err));
return 1;
}
err = pthread_join(tid, NULL);
if (err){
printf("pthread_join returns %d\n", err);
return 1;
}
return 0;
}
--------------------------------------------------------------------
The result is as follows:
----------------------------------------------------------
$ ./test_pthread_create
errno 12: Cannot allocate memory
pthread_cretate returns 12: Cannot allocate memory
----------------------------------------------------------
--
Summary: pthread_create returns ENOMEM instead of EAGAIN
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: nptl
AssignedTo: drepper at redhat dot com
ReportedBy: wangf at cn dot fujitsu dot com
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=5245
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug nptl/5245] pthread_create returns ENOMEM instead of EAGAIN
2007-11-02 3:43 [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN wangf at cn dot fujitsu dot com
@ 2007-11-02 3:47 ` wangf at cn dot fujitsu dot com
2007-11-02 3:49 ` wangf at cn dot fujitsu dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: wangf at cn dot fujitsu dot com @ 2007-11-02 3:47 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From wangf at cn dot fujitsu dot com 2007-11-02 03:47 -------
Created an attachment (id=2073)
--> (http://sourceware.org/bugzilla/attachment.cgi?id=2073&action=view)
patch to fix the bug
--
http://sourceware.org/bugzilla/show_bug.cgi?id=5245
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug nptl/5245] pthread_create returns ENOMEM instead of EAGAIN
2007-11-02 3:43 [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN wangf at cn dot fujitsu dot com
2007-11-02 3:47 ` [Bug nptl/5245] " wangf at cn dot fujitsu dot com
@ 2007-11-02 3:49 ` wangf at cn dot fujitsu dot com
2007-11-08 0:44 ` drepper at redhat dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: wangf at cn dot fujitsu dot com @ 2007-11-02 3:49 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From wangf at cn dot fujitsu dot com 2007-11-02 03:49 -------
This is tested with glibc version 2.7.
And the attached patch fixes the bug.
After applying the patch, the test result is:
-----------------------------------------------------------
$ ./test_pthread_create
errno 12: Cannot allocate memory
pthread_cretate returns 11: Resource temporarily unavailable
-----------------------------------------------------------
--
What |Removed |Added
----------------------------------------------------------------------------
Summary|pthread_create returns |pthread_create returns
|ENOMEM instead of EAGAIN |ENOMEM instead of EAGAIN
http://sourceware.org/bugzilla/show_bug.cgi?id=5245
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug nptl/5245] pthread_create returns ENOMEM instead of EAGAIN
2007-11-02 3:43 [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN wangf at cn dot fujitsu dot com
2007-11-02 3:47 ` [Bug nptl/5245] " wangf at cn dot fujitsu dot com
2007-11-02 3:49 ` wangf at cn dot fujitsu dot com
@ 2007-11-08 0:44 ` drepper at redhat dot com
2007-11-08 1:07 ` wangf at cn dot fujitsu dot com
2007-11-08 17:25 ` drepper at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: drepper at redhat dot com @ 2007-11-08 0:44 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From drepper at redhat dot com 2007-11-08 00:44 -------
Fixed in cvs trunk but noth with the patch you provided.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://sourceware.org/bugzilla/show_bug.cgi?id=5245
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug nptl/5245] pthread_create returns ENOMEM instead of EAGAIN
2007-11-02 3:43 [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN wangf at cn dot fujitsu dot com
` (2 preceding siblings ...)
2007-11-08 0:44 ` drepper at redhat dot com
@ 2007-11-08 1:07 ` wangf at cn dot fujitsu dot com
2007-11-08 17:25 ` drepper at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: wangf at cn dot fujitsu dot com @ 2007-11-08 1:07 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From wangf at cn dot fujitsu dot com 2007-11-08 01:07 -------
pthread_create() calls the static function creat_thread(), and this funciton
at last calls __clone(), __clone() may set errno to ENOMEM. So why not check
the ENOMEM in pthread_create(), it won't miss any ENOMEM case.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |
http://sourceware.org/bugzilla/show_bug.cgi?id=5245
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug nptl/5245] pthread_create returns ENOMEM instead of EAGAIN
2007-11-02 3:43 [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN wangf at cn dot fujitsu dot com
` (3 preceding siblings ...)
2007-11-08 1:07 ` wangf at cn dot fujitsu dot com
@ 2007-11-08 17:25 ` drepper at redhat dot com
4 siblings, 0 replies; 6+ messages in thread
From: drepper at redhat dot com @ 2007-11-08 17:25 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From drepper at redhat dot com 2007-11-08 17:25 -------
(In reply to comment #4)
> So why not check
> the ENOMEM in pthread_create(), it won't miss any ENOMEM case.
Because unlike crappy proprietary software we don't settle for garbage.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |FIXED
http://sourceware.org/bugzilla/show_bug.cgi?id=5245
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-11-08 17:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-02 3:43 [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN wangf at cn dot fujitsu dot com
2007-11-02 3:47 ` [Bug nptl/5245] " wangf at cn dot fujitsu dot com
2007-11-02 3:49 ` wangf at cn dot fujitsu dot com
2007-11-08 0:44 ` drepper at redhat dot com
2007-11-08 1:07 ` wangf at cn dot fujitsu dot com
2007-11-08 17:25 ` drepper at redhat dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).