Hi all,
I got this simple program creating 5 threads. #include <stdio.h> #include <stdlib.h> #include <pthread.h>
void* donothing(void* n) { int i; for (;;i++) sleep(i); }
int main() { pthread_t t[5]; int i = 0; for (i = 0; i<5; i++) pthread_create(&t[i], NULL, donothing, NULL);
donothing(NULL); return 0;
}
Running this program, I see with ps xau, seven threads:
praise 10557 92.3 0.1 11912 376 pts/3 R 17:09 0:30 ./a.out praise 10558 0.0 0.1 11912 376 pts/3 S 17:09 0:00 ./a.out praise 10559 0.0 0.1 11912 376 pts/3 S 17:09 0:00 ./a.out praise 10560 0.0 0.1 11912 376 pts/3 S 17:09 0:00 ./a.out praise 10561 0.0 0.1 11912 376 pts/3 S 17:09 0:00 ./a.out praise 10562 0.0 0.1 11912 376 pts/3 S 17:09 0:00 ./a.out praise 10563 0.0 0.1 11912 376 pts/3 S 17:09 0:00 ./a.out
Why are they 7 and not 6? I create 5 threads, plus the main thread I thought I had to get 6 threads. Why I see 7 threads istead? I don't know the implementation details, but you should have the main
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, 16 Dec 2003 17:13:54 +0100 praisetazio <praisetazio@tiscalinet.it> wrote: thread + 1 internal thread used by the thread package for dispatching et. al. - -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) iD8DBQE/32Dj+wA+1cUGHqkRAu2CAJ9/aboJgceDBO5hbPegSXpPhZUKNwCfQ90m 5xRBM2LM8ZcxTKBVP9h/SWI= =cCCz -----END PGP SIGNATURE-----