Please see the attached program.
It fails with the following output:
spawning thread #0
spawned thread #0 (thr_id=8053400)
spawning thread #1
spawn failure: Resource temporarily unavailable
ktrace shows the following information:
27360 thread GIO fd 2 wrote 19 bytes
"spawning thread #1
27360 thread RET write 19/0x13
27360 thread CALL kse_create(0x804bf0c,0)
27360 thread RET kse_create -1 errno 67 Too many processes
It seems that the problem occurs because flag THR_NEW_LWP, included into default set of ACE thread flags,
is interpreted by ACE library as an instruction to call pthread_setconcurrency with concurrency level
set to current number of threads created through ACE. FreeBSD libpthread refuses to set
concurrency higher than a number of CPUs available. ACE library treats pthread_setconcurrency() failure
as a fatal failure for thread creation.
Any solution for this problem should probably be submitted to ACE maintainers for
inclusion into ACE platform-specific source base.
Fix: Workaround: use libthr as a threading library
Solution 1: change a meaning of THR_NEW_LWP on FreeBSD as term "LWP" is not directly
applicable to FreeBSD threading model. Reasonable approach is to alias THR_NEW_LWP
Solutuion 2: do not treat failure of pthread_setconcurrency() as a fatal error
for thread creation.
No patches, sorry.
How-To-Repeat: 1. Change the attached program so that thr_num variable is greater than the number of CPUs on your test machine.
2. Compile the attached program:
$ c++ thread.cpp -o thread -I /usr/local/include -L /usr/local/lib -lACE -pthread
3. Make sure that libpthread is used as your thread support library:
$ ldd thread
libACE.so.5 => /usr/local/lib/libACE.so.5 (0x48077000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x48196000)
libm.so.4 => /lib/libm.so.4 (0x4826c000)
libpthread.so.2 => /usr/lib/libpthread.so.2 (0x48283000)
libc.so.6 => /lib/libc.so.6 (0x482aa000)
4. run the program
Over to maintainer
I investigated it. It's a bug in 6.x. It works like charm on 7-CURRENT.
And I like solution #1. I'll make a patch with the solution (hmm, most
like a work around) for 6.x.
Oops. Sorry. My box with 7-CURRENT just has 4 CPU. So I war wrong about
A fix committed.
sem 2006-12-03 19:42:31 UTC
FreeBSD ports repository
- A work around for creating threads with THR_NEW_LWP.
LWP is not directly applicable to FreeBSD threading model.
Submitted by: Andriy Gapon <avg at icyb.net.ua>
Revision Changes Path
1.12 +1 -0 ports/devel/ace/Makefile
1.1 +11 -0 ports/devel/ace/files/patch-ace-os_include-os_pthread.h (new)
firstname.lastname@example.org mailing list
To unsubscribe, send any mail to "email@example.com"