Subject: pthread_create() and more than 1 CPU
To: None <email@example.com>
From: Michael Graff <firstname.lastname@example.org>
Date: 12/02/2004 12:22:18
So, I have a little program I'm using to torture test a bit of code I have to
make certain I have the locking code right.
I am using pthread_create() to create the threads. They all start, then
eventually exit. However, at no time does ps display more than one LWP in
use, and at no time does it consume all the CPU resources available on the
machine. It seems to use only one CPU.
I have set the undocumented and magical value PTHREAD_CONCURRENCY in my
environment to 2, and now it runs with 2 LWPs and uses 200% CPU. Whee.
Would it Really Break anything if I applied this patch? It will make it so a
process by default uses ncpu for its maximum concurrency, which really seems
more in line with every other OS out there. Other than Solaris, of course,
where pthread_setconcurrency() must be called to set the limit up to ncpu. I
suppose we could implement that as well, but I'd rather see libpthread do
what most people expect -- use ncpu by default.
RCS file: /cvsroot/src/lib/libpthread/pthread.c,v
retrieving revision 1.36
diff -u -r1.36 pthread.c
--- pthread.c 12 Aug 2004 10:54:13 -0000 1.36
+++ pthread.c 2 Dec 2004 20:19:56 -0000
@@ -145,7 +145,7 @@
/* Find out requested/possible concurrency */
- pthread__maxconcurrency = 1;
+ pthread__maxconcurrency = ncpu;
p = getenv("PTHREAD_CONCURRENCY");
pthread__maxconcurrency = atoi(p);