Re: Processes vs Threads

From: Paul Beardsell <psb_at_sambusys.demon.co.uk>
Date: Fri, 11 Nov 1994 03:22:14 +0000
Message-ID: <784524134snz_at_sambusys.demon.co.uk>


In article <39la86$5p7_at_newsflash.concordia.ca>

           andrew_at_gmvt4.concordia.ca "Andrew Francis" writes:

> In article <784051057snz_at_sambusys.demon.co.uk>
> psb_at_sambusys.demon.co.uk writes:
>
> In article <3984pm$1es_at_mail.fwi.uva.nl>
> casper_at_fwi.uva.nl "Casper H.S. Dik" writes:
>
> CD>Fork() is still very expensive. More expensive than creating threads.
> CD>Even the copy-on-write implementations are expensive (in the order
>
> [lines deleted]
>
> PB>Tell me what pThreadCreate() doesn't do that fork() does do?
>
> First thing I can think the pthread_create() doesn't do is create a
> new Unix process.

Err, well, yes. But what actually happens when you create a new process as opposed to creating a new thread? If you actually count the instructions executed, the amount of memory allocated, the overhead of the thread scheduler etc etc then it is not obvious that creating/running a thread is cheaper than creating/running a process.

> PB>What locking can threads do than is cheaper than semaphores used by
> PB>co-operating Unix processes?
>
> Unix System V style semaphores are expensive since atomicity is ensured
> by storing semaphores and manipulating them in the kernel. Since the Unix
> kernel cannot be interrupted, this is safe. However this makes semaphores
> costly. Also, Unix semaphores are very awkward and difficult to use. Since
> I believe most thread packages try to avoid making system calls, they will
> be faster. I expect them to be considerable faster.

Semaphores are awkward, I grant you. But just do what I did: write a few macros and 2 or 3 small functions to manipulate them for you. See also the eponymous Stevens book.

What type of application other than number crunching doesn't do system calls all the time? Please just name a few. Because then I'll save any consideration of threads until I have the occasion to write one of the apps.

> --Andrew
 

-- 
Paul Beardsell                          SAM Business Systems Ltd
~~~~~~~~~~~~~~                          21 Finn House, Bevenden St,
pbeardsell_at_cix.compulink.co.uk          London, N1-6BN, UK.
psb_at_sambusys.demon.co.uk                (+44 or 0)71 608-2391
Received on Fri Nov 11 1994 - 04:22:14 CET

Original text of this message