views:

62

answers:

2

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?

A: 

I've found this. Seems to be a system limitation, but I'm not completely sure. However, that site provides a workaround.

jkramer
A: 

I ran the program under strace and saw the following:

mmap(NULL, 10489856, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS|0x40, -1, 0) = -1 ENOMEM (Cannot allocate memory)
mmap(NULL, 10489856, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)

UPDATE: Don't ask me why, but the following change fixes the issue:

pthread_attr_setscope(pattr, PTHREAD_SCOPE_SYSTEM);
Lance Purple