Pre-emptive or co-operative concurrency (was: Concurrency)

John Meacham john at
Thu Mar 30 06:04:06 EST 2006

On Thu, Mar 30, 2006 at 10:54:01AM +0100, Simon Marlow wrote:
> 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.

it should be noted that I don't consider this a bug, but a design
choice. of course, since you made the choice differently then for GHC it
is a bug :)

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

well, as preemptive as the pthreads implementation at least. which is
usually very, but not so with some userspace implementations of

Both are allowed by the standard so "counting" on preemption is a bad
idea in general, even with ghc. (though, perhaps this isn't true, ghc
has its own mini-threads underneath OS threads in -threaded mode if I
understand it properly and that makes things less simplistic.)

however, this is all just reiteration of the "never count on the
scheduler" rule when writing threaded apps when you didn't write the
operating system :) (hard real-time bug-free systems exempt)


John Meacham - ⑆⑆john⑈

More information about the Haskell-prime mailing list