| ... | @@ -137,20 +137,24 @@ to avoid using the term. |
... | @@ -137,20 +137,24 @@ to avoid using the term. |
|
|
|
|
|
|
|
|
|
|
|
|
**Scheduling.**
|
|
**Scheduling.**
|
|
|
All current (and likely future) implementations of
|
|
Most current implementations of
|
|
|
concurrency in Haskell use non-preemptive scheduling. That is, there are
|
|
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.
|
|
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.
|
|
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 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.
|
|
- 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.
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
|
|
|
|
| ... | | ... | |