9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] proccreate() and threadcreate()?
@ 2002-06-04 15:55 rob pike, esq.
  0 siblings, 0 replies; 4+ messages in thread
From: rob pike, esq. @ 2002-06-04 15:55 UTC (permalink / raw)
  To: 9fans

Sape should post his slides from this course, but this set has a section
about how to use them you might find interesting.

	http://plan9.bell-labs.com/cm/cs/who/rob/lec5.pdf

Meanwhile, you're right that the man page seems to have lost, if it
ever had, a concise description of the relationship between procs
and threads.  They are mutually schedulable, but different: a proc
represents a new process in the operating system that may block,
for example in a read call, while other processes continue to run.
Threads are coroutines within a proc; if a thread blocks in a system
call, all threads in that proc also block. On the other hand, threads
within a proc do not execute in parallel at the instruction level, so
access to shared variables is safer between threads than procs.

But see the slides above for a description of how to use them in
practice.  Also I believe the Acme paper has a description.

-rob



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] proccreate() and threadcreate()?
@ 2002-06-04 15:56 Sape Mullender
  0 siblings, 0 replies; 4+ messages in thread
From: Sape Mullender @ 2002-06-04 15:56 UTC (permalink / raw)
  To: 9fans

> 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] proccreate() and threadcreate()?
@ 2002-06-04 15:54 Russ Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Russ Cox @ 2002-06-04 15:54 UTC (permalink / raw)
  To: 9fans

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

Threads are arranged into procs.  Threads within
a proc are scheduled cooperatively whereas the procs
are scheduled preemptively by the Plan 9 scheduler.
Threadcreate makes a new thread in the same proc
as the calling thread.  Proccreate makes a new
proc and starts a new thread running in it.

The thread(2) man page describes this.  For more information
on threads and procs see the Alef User's Guide, linked at
http://plan9.bell-labs.com/~rsc/thread.html#8

Russ


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [9fans] proccreate() and threadcreate()?
@ 2002-06-04 11:57 Ish Rattan
  0 siblings, 0 replies; 4+ messages in thread
From: Ish Rattan @ 2002-06-04 11:57 UTC (permalink / raw)
  To: 9fans


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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-06-04 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-04 15:55 [9fans] proccreate() and threadcreate()? rob pike, esq.
  -- strict thread matches above, loose matches on Subject: below --
2002-06-04 15:56 Sape Mullender
2002-06-04 15:54 Russ Cox
2002-06-04 11:57 Ish Rattan

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