Re: pthread_create creating 2 threads on first call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 20, 2002 at 09:59:27PM +0200, Osman Çinar Eren wrote:
> that should probably be the thread created by the kernel to deal all the
> threads created by your program.
> regards.

It's not created by the kernel implicitly (remember, threads are just
normal processes that share some stuff and clone is just an extended
fork). It's created by the pthread library as a master thread to
coordinate thread attaching and detaching (found this out by looking in
the code). 

I think it's because the interface requires that any thread can join any
other thread. But linux only supports waiting for children. So when
pthread library is first used, it starts a master thread that then
clones the actual threads (actualy, the original process must become the
master and the first child continues it's work)

> -----Original Message-----
> From: Nguyen, NguyenX D [mailto:nguyenx.d.nguyen@intel.com]
> Sent: Wednesday, November 20, 2002 9:53 PM
> To: kernelnewbies@nl.linux.org
> Subject: pthread_create creating 2 threads on first call
> 
> 
> Hello folks,
> 
> I have a simple demo program that call pthread_create
> 5 times with identical parameters.  On the FIRST call 
> to pthread_create, two threads are created. One of these 
> thread is what I am expecting.  On subsequent call to 
> pthread_create, only one thread is created as expected.
> 
> Does anyone happen to know why on the FIRST call to
> pthread_create, two threads are created?  What does the
> extra one do?  Many thanks!
> 
> - Nguyen
> 
> ps: I am compiling with the -pthread switch.
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux