From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,2aedba6752dd2388 X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1993-10-12 13:18:39 PST Path: gmd.de!xlink.net!howland.reston.ans.net!pipex!uunet!bloom-beacon.mit.edu!paperboy.osf.org!rsalz From: rsalz@osf.org (Rich Salz) Newsgroups: comp.unix.osf.misc Subject: Re: Threads better than forks? Date: 12 Oct 1993 19:19:36 GMT Organization: Open Software Foundation Message-ID: <29f008$2fh@paperboy.osf.org> References: <1993Oct11.170510.13690@mnemosyne.cs.du.edu> NNTP-Posting-Host: sulphur.osf.org Keywords: threads, fork, exec, DCE In <1993Oct11.170510.13690@mnemosyne.cs.du.edu> tgeorges@nyx.cs.du.edu (Thomas Georges) writes: > "What's the advantage of using threads over fork/exec with signals?" There is really only one true difference: all threads within a process share that process's state (e.g., global variables, open files, etc). The other differences, e.g., "forks are more expensive" and "scheduling is different" are not architectural differences. These, and other differences mentioned on the net, vary among operating systems, and hardware. Okay, given global shared state what can you do with it? Here's a simple use. A client knows that there are 10 servers out there that can solve its problem. It spawns ten threads, each one doing an RPC. The first one that comes back sends a cancel message to the other nine. Suppose you want to keep 10 "calculators" busy each doing a partitioned part of, say, a Mandelbrot calculation. Each thread just pulls another chunk of the problem out of a pool. (Call it tuple-space and you just invented inverted Linda. :-) Correctly programming with threads is difficult. There's a book on Modula-3 that has a great chapter on how to use threads; it was written by Andrew Birrell and is a slight revision of a wonderful DEC technical paper. The book is worth it for just this chapter. /r$