Pre-emptive or co-operative concurrency (was: Concurrency)
Simon Marlow
simonmar at microsoft.com
Thu Mar 30 04:54:01 EST 2006
On 29 March 2006 17:21, Claus Reinke wrote:
> all of the concurrency implementations discussed so far seem to
> be based on a mixture of preemptive and non-premptive scheduling.
> context-switches happen only on specific events, which every
> thread will usually engage in, although it need not always do so:
>
> 1 only calls to yield
> 2 any calls to concurrency library api
> 3 any allocation
Not true - in GHC with SMP a thread doing no allocation can be running
concurrently with any number of other threads. It's only the
single-threaded implementation that has this bug where a thread that
doesn't allocate can starve the other threads. In fact, even on a
uniprocessor, you can use GHC's SMP mode to work around the bug by
pretending you have 2 CPUs.
GHC's SMP mode is truly preemptive, operations from multiple threads can
be arbitrarily interleaved. So let's stop saying that all known
implementations are non-preemptive, please ;-)
Cheers,
Simon
More information about the Haskell-prime
mailing list