9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Sape Mullender <sape@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] proccreate() and threadcreate()?
Date: Tue,  4 Jun 2002 11:56:36 -0400	[thread overview]
Message-ID: <2e623eb25383e89b160cada39749b44c@plan9.bell-labs.com> (raw)

> 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



             reply	other threads:[~2002-06-04 15:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-04 15:56 Sape Mullender [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-06-04 15:55 rob pike, esq.
2002-06-04 15:54 Russ Cox
2002-06-04 11:57 Ish Rattan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e623eb25383e89b160cada39749b44c@plan9.bell-labs.com \
    --to=sape@plan9.bell-labs.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).