Hello All! On Monday 11 January 2010 19:55:43 Lennart Sorensen wrote: > On Mon, Jan 11, 2010 at 07:51:12PM +0100, Andrea Tassi wrote: > > I performed some tests with the uClibc 0.9.30.1 about the > > multithreading. I have a problem: when I execute this program, [--SNIP--] > > it should create exactly 8 threads but with "ps" I can see that the > > instruction pthread_create(.....) forks: you can see that there are 10 > > instances with different PIDs of the sane example program (called > > test): > > 1426 root 16952 S /tmp/test > > 1427 root 16952 S /tmp/test > > 1428 root 16952 S /tmp/test > > 1429 root 16952 S /tmp/test > > 1430 root 16952 S /tmp/test > > 1431 root 16952 S /tmp/test > > 1432 root 16952 S /tmp/test > > 1433 root 16952 S /tmp/test > > 1434 root 16952 S /tmp/test > > 1435 root 16952 S /tmp/test > > Could you explain me how is this possible? Thank you. > Linux is allowed to represent threads however it wants. If the threads > were done in user space entirely (including scheduling of threads) then > you should of course have only one pid. But since the kernel helps out > with scheduling and such, it is perfectly reasonable to treat them as > lightweight processes. They somewhat are after all. They have a stack, > an instruction pointer, a cpu state, etc. They just don't have their > own memory space.
uClibc 0.9.30.1 implements threads as LinuxThreads, that is basically a trick with clone() and such, so threads are emulated with different processes. With LinuxThreads, you'll get one process per thread, in your case 8 processes. But managing the threads are done by two other "master" processes, that gives you a ninth and tenth processes. That was also the case with glibc, before there was NPTL, as glibc also implemented threads with LinuxThreads. Regards, Yann E. MORIN. -- .-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | `------------------------------^-------^------------------^--------------------' _______________________________________________ uClibc mailing list [email protected] http://lists.busybox.net/mailman/listinfo/uclibc
