| ... | ... | @@ -93,6 +93,56 @@ For (2), one option is [ForeignBlocking](foreign-blocking). |
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
# Terminology
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Pre-emption** means that (1) threads have priority levels, and (2) that a
|
|
|
|
higher priority thread can steal the processor from a currently-running
|
|
|
|
lower priority thread, and (3) it can do so "immediately" it needs to,
|
|
|
|
without waiting for some "safe" synchronisation point.
|
|
|
|
By these criteria, none of the current Haskell implementations are
|
|
|
|
pre-emptive, because no API assigns priorities to threads. So let's try
|
|
|
|
to avoid using the term.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Fairness** can be defined by two main criteria:
|
|
|
|
|
|
|
|
|
|
|
|
- No runnable process will be indefinitely delayed.
|
|
|
|
- No thread can be blocked indefinitely on an MVar unless another thread holds the MVar indefinitely.
|
|
|
|
|
|
|
|
|
|
|
|
**Non-blocking foreign call** as commonly used, actually means a foreign call that \*can\* block. As a
|
|
|
|
consequence of the fairness policy, one wishes to place the requirement on
|
|
|
|
implementations that such a blocking foreign call _should_not_
|
|
|
|
block progress of other Haskell threads. The thread-nature of the
|
|
|
|
foreign call is "blocking". The Haskell-API nature is desired to be
|
|
|
|
"non-blocking".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Scheduling.**
|
|
|
|
All current (and likely future) 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 yhc, yield is inserted after some count of bytecode instructions.
|
|
|
|
|
|
|
|
|
|
|
|
Arguably, Hugs has made the wrong choice from a fairness point of view,
|
|
|
|
but moving the position of the yield, or inserting them more frequently,
|
|
|
|
should not be a big deal.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
# Levels
|
|
|
|
|
|
|
|
|
| ... | ... | |