From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6636 invoked by alias); 2 Nov 2007 03:43:45 -0000 Received: (qmail 6354 invoked by uid 48); 2 Nov 2007 03:43:27 -0000 Date: Fri, 02 Nov 2007 03:43:00 -0000 From: "wangf at cn dot fujitsu dot com" To: glibc-bugs@sources.redhat.com Message-ID: <20071102034326.5245.wangf@cn.fujitsu.com> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug nptl/5245] New: pthread_create returns ENOMEM instead of EAGAIN X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2007-11/txt/msg00007.txt.bz2 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 #include #include #include #include #include #include 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.