| ... | ... | @@ -106,18 +106,21 @@ to avoid using the term. |
|
|
|
**Concurrent foreign call** means a foreign call that should run concurrently with other Haskell threads. It is a requirement of "fairness" (above) that a foreign call should not prevent other threads from making progress indefinitely. Note that we used to use the term **non-blocking foreign call** here, but that lead to confusion with "foreign calls that block", which are foreign calls that may wait indefinitely for some resource, such as reading data from a socket. "foreign calls that block" are the main reason for wanting support for concurrent foreign calls.
|
|
|
|
|
|
|
|
**Scheduling.**
|
|
|
|
All current (and likely future) implementations of
|
|
|
|
Most current implementations of
|
|
|
|
concurrency in Haskell use non-preemptive scheduling. That is, there are
|
|
|
|
explicit time points at which any one thread can *yield*, allowing other threads to run.
|
|
|
|
The only differences between implementations are in the granularity and positioning of the yield.
|
|
|
|
|
|
|
|
- For Hugs, yield is inserted at certain I/O actions.
|
|
|
|
- For ghc, yield is inserted after some count of allocations.
|
|
|
|
- For ghc in non-SMP mode, yield is inserted after some count of allocations.
|
|
|
|
- For yhc, yield is inserted after some count of bytecode instructions.
|
|
|
|
|
|
|
|
|
|
|
|
Arguably, Hugs has made the wrong choice from a fairness point of view. It would be possible to make Hugs yield more often, such as in IO-monad's bind operator, but even this wouldn't be quite enough for fairness, because a thread might hang indefinitely performing a non-IO computation. Yielding outside of the IO monad in Hugs doesn't seem possible without overhauling the concurrency implementation completely.
|
|
|
|
|
|
|
|
|
|
|
|
The notable exception to the above is GHC in SMP mode, which can run multiple Haskell threads simultaneously in separate OS threads, and hence simultaneously on multiple CPUs if available. This implementation is truly preemptive.
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
# Levels
|
| ... | ... | |