Received: from SOUTH-STATION-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA06397; Fri, 29 Sep 95 15:58:02 EDT
Received: from JIMI.MIT.EDU by MIT.EDU with SMTP
	id AA25693; Fri, 29 Sep 95 15:57:34 EDT
Received: by jimi.MIT.EDU (5.57/4.7) id AA16587; Fri, 29 Sep 95 15:57:54 -0400
Message-Id: <9509291957.AA16587@jimi.MIT.EDU>
To: bazyar@hypermall.com (Jawaid Bazyar)
Cc: proven@MIT.EDU
Subject: Re: Theory of Pthreads 
In-Reply-To: Your message of "Fri, 29 Sep 1995 09:51:04 -0000."
             <m0syc5w-000BXSC@hypermall.com> 
Date: Fri, 29 Sep 1995 15:57:54 EDT
From: Christopher Provenzano  <proven@MIT.EDU>


> 
>   Just a quick Q: how the hell does pthreads work? I've done a lot
> of OS work in my day, so I know how threads and processes etc.
> all work. What I mean, in particular, is how do you integrate
> pthreads with the kernel such that programs like test_sock_1 
> can have multiple threads running with some sleeping inside the
> kernel.
> 
>   Solaris would be easy, since it has threads. But SunOS doesn't have
> kernel threads, hence my confusion.  
> 
>   Any light you could shed on this, or any documents you could point
> me to that already explain this, would be most appreciated.
> 
>   Thanks in advance.
> 
> -- 
>  Jawaid Bazyar              |   Like UNIX? Like your Apple IIGS? Then ask
>  Procyon, Inc.              |   me about GNO/ME for the Apple IIgs!   
>  bazyar@hypermall.com       |   P.O Box 620334    (Sequential: 303-666-4549)
>  --The Future is Now!--     |   Littleton, CO 80162-0334   (303) 781-3273

Actually there isn't any integration with the kernel or kernel threads.
(Future releases will have this integration for systems with some sort of
kernel thread support.) Everything is done by intercepting the syscall at 
the user level. If such a system call would potentially block it tries
a nonblocking variant and if it fails it switches to a different thread.
As for sleep(), it uses setitimer() and keeps a list of all threads waiting 
in sleep() (or some timeout). Also all signals are intercepted in pthreads 
to determine if they are for the pthread kernel (to wake some thread up or
something) or for the users code.

There is a lot of code to make this whole process as transparant to the
user code and to make it as effecient as possible.

CAP
