Bug 105794 - devel/ace: can not create more than ncpu threads with default thread flags
Summary: devel/ace: can not create more than ncpu threads with default thread flags
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Sergey Matveychuk
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-23 16:50 UTC by Andriy Gapon
Modified: 2006-12-03 19:50 UTC (History)
1 user (show)

See Also:


Attachments
thread.cpp (1.01 KB, text/plain)
2006-11-23 16:50 UTC, Andriy Gapon
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andriy Gapon 2006-11-23 16:50:16 UTC
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
Exit 71

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
to THR_SCOPE_SYSTEM.

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
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
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2006-11-23 16:50:30 UTC
Responsible Changed
From-To: freebsd-ports-bugs->sem

Over to maintainer
Comment 2 Sergey Matveychuk freebsd_committer freebsd_triage 2006-12-03 14:50:09 UTC
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.

-- 
Dixi.
Sem.
Comment 3 Sergey Matveychuk freebsd_committer freebsd_triage 2006-12-03 16:32:32 UTC
Oops. Sorry. My box with 7-CURRENT just has 4 CPU. So I war wrong about
above.

-- 
Dixi.
Sem.
Comment 4 Sergey Matveychuk freebsd_committer freebsd_triage 2006-12-03 19:43:59 UTC
State Changed
From-To: open->closed

A fix committed.
Comment 5 dfilter service freebsd_committer freebsd_triage 2006-12-03 19:46:58 UTC
sem         2006-12-03 19:42:31 UTC

  FreeBSD ports repository

  Modified files:
    devel/ace            Makefile 
  Added files:
    devel/ace/files      patch-ace-os_include-os_pthread.h 
  Log:
  - A work around for creating threads with THR_NEW_LWP.
    LWP is not directly applicable to FreeBSD threading model.
  
  PR:             ports/105794
  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)
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"