From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <2e623eb25383e89b160cada39749b44c@plan9.bell-labs.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] proccreate() and threadcreate()? From: Sape Mullender MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Tue, 4 Jun 2002 11:56:36 -0400 Topicbox-Message-UUID: a4d68edc-eaca-11e9-9e20-41e7f4b1d025 > It is a nive question. Will somebody tell me the differences > between proccreate() and threadcreate() functions? Programming > point of view both seem to behave exactly the same! > > -ishwar The Plan 9 model for parallel programming distinguishes between procs and threads. A proc is scheduled by the operating system. If you have two procs, both procs (appear to) run simultaneously. On a multiprocessor, they really run simultaneously. Threads are essentially coroutines. Each proc can have one or more threads in it. The threads within a proc take turns getting the processor. Two threads in one proc can never run simultaneously. When a thread gives up the processor, another thread in the same proc can run. Threads give up the processor by communicating over channels, or by calling yield(). They do NOT give up the processor by making read or write system calls. A thread that blocks on a read or write, also prevents other threads in the same proc from running. Typical Plan 9 programs have a single proc containing many worker threads picking up work from shared data structures or from messages sent over channels. These threads do not need to lock any of the shared data strcutures they use because they are only shared by other threads in the same proc -- and those threads will never run concurrently with the thread reading or modifying the data structure. I/O is done by threads in other procs, one thread per I/O proc. The threads in I/O procs can block on reads and writes without blocking other threads -- there's only one in the proc. Worker threads communicate with I/O threads using channels, which are protected by the thread library from concurrent access problems. Threadcreate() creates a new thread in the current proc. Proccreate() creates a new proc and a single new thread in that proc. Sape