Cannot create more than 1 or 4 threads!
From: Paavo (paavo_at_ebi.ee)
Date: 10/31/05
- Next message: houghi: "CLI fun with YaST"
- Previous message: Detlef Müller: "Re: problem installing software"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Oct 2005 05:09:12 -0800
We have stumped on a strange behaviour, stripped down to the simplest
pthread program below; it seems I cannot create more than 1 or 4
threads, depending on the machine (pthread_create() returns EAGAIN).
Both machines are SuSE Linux 8.2, so I suspect this might be related.
On another machine (RedHat) there is no problem. Obviously this has to
be some initialisation or user privileges' issue, but google search has
not releaved anything relevant. Thanks in advance for help!
/// a.cpp
#ifndef _REENTRANT
#define _REENTRANT
#endif
#include <pthread.h>
#include <stdio.h>
void* g(void* i) {
fprintf(stdout, "Hi world: %p\n", i);
return i;
}
int main() {
int i;
pthread_t h[10];
for (i=1; i<=10; ++i) {
int res = pthread_create(&h[i-1], 0, &g, (void*) i);
fprintf(stdout, "pthread_create (0=OK, 11=EAGAIN): %d\n", res);
}
for (i=1; i<=10; ++i) {
void* code;
int res = pthread_join(h[i-1], &code);
fprintf(stdout, "pthread_join: %d, thread termination code: %p\n",
res, code);
}
return 0;
}
----------------
gcc -Wall -lpthread a.c
---------- Results on the first machine:
ALT: tmp>./a.out
Hi world: 0x1
pthread_create (0=OK, 11=EAGAIN): 0
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_join: 0, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
pthread_join: 3, thread termination code: 0x1
ALT: tmp>cat /etc/SuSE-release
SuSE Linux 8.2 (i586)
VERSION = 8.2
ALT: tmp>uname -a
Linux altair 2.4.20-64GB-SMP #1 SMP Fri Mar 12 15:35:09 UTC 2004 i686
unknown unknown GNU/Linux
ALT: tmp>gcc -v
Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.3/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada
--disable-checking --libdir=/usr/lib --enable-libgcj
--with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-__cxa_atexit
i586-suse-linux
Thread model: posix
gcc version 3.3.3 (SuSE Linux)
-------- Results on the second machine:
paavo@sirius:~/tmp> ./a.out
Hi world: 0x1
pthread_create (0=OK, 11=EAGAIN): 0
Hi world: 0x2
pthread_create (0=OK, 11=EAGAIN): 0
Hi world: 0x3
pthread_create (0=OK, 11=EAGAIN): 0
Hi world: 0x4
pthread_create (0=OK, 11=EAGAIN): 0
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_create (0=OK, 11=EAGAIN): 11
pthread_join: 0, thread termination code: 0x1
pthread_join: 0, thread termination code: 0x2
pthread_join: 0, thread termination code: 0x3
pthread_join: 0, thread termination code: 0x4
pthread_join: 3, thread termination code: 0x4
pthread_join: 3, thread termination code: 0x4
pthread_join: 3, thread termination code: 0x4
pthread_join: 3, thread termination code: 0x4
pthread_join: 3, thread termination code: 0x4
pthread_join: 3, thread termination code: 0x4
paavo@sirius:~/tmp> cat /etc/SuSE-release
SuSE Linux 8.2 (i586)
VERSION = 8.2
paavo@sirius:~/tmp> uname -a
Linux sirius 2.4.20-64GB-SMP #1 SMP Wed Apr 16 14:44:01 UTC 2003 i686
unknown unknown GNU/Linux
paavo@sirius:~/tmp> gcc -v
Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.3/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada
--disable-checking --libdir=/usr/lib --enable-libgcj
--with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-__cxa_atexit
i586-suse-linux
Thread model: posix
gcc version 3.3.3 (SuSE Linux)
- Next message: houghi: "CLI fun with YaST"
- Previous message: Detlef Müller: "Re: problem installing software"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]