Re: waitpid on a thread.

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

 



On Sun, Dec 08, 2002 at 09:27:49PM -0800, Sharath wrote:
> Amit,
> 
> the threading library on Linux is a a bit different
> from the normal 'threads'.
> 
> Strictly threads are not children of a process as a
> fork(...) does. When a child of a process terminated,
> the parent process gets a SIGCHLD. However when a
> thread terminates is doesn't.
> 
> The way threading is implemented on linux (where every
> thread is represented as a child) is a quirk.
> 
> The thread (though it appears as a child) is in fact
> *not a true cild* of the process hence waitpid(...)
> rightly returns. You shouldn't be using waitpid(...)
> to wait on a thread rather use pthread_join(...)  but
> then you need to pass on the pthread_t that you got
> when you created it.

It is a true child. But it's a child of the pthreads master thread. When
you first pthread_create, it clones and the _child_ continues on, while
the _parent_ becomes the master thread. Then, the child (which continues
the work of the original process) sends a message to the master and the
master clones the new thread. When you call pthread_join, the message is
passed to the master and the master issues waitpid. That's the only way
how to assure, that any thread can join any other thread.

-------------------------------------------------------------------------------
						 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