|
|
|
|
|
by haxen
2142 days ago
|
|
Without the very last point, forced preemption, they would indeed be cooperative because not calling any blocking method would make them non-cooperative. This is exactly the same as within the "colored" subspace in a language that has this distinction. As long as all the functions you call are suspendable, you equally have no idea which one will actually suspend. So, without forced preemption based on GC safepoints, and as long as there is any blocking operation left in the library, Loom qualifies as a cooperative multithreading system. |
|
If user code cannot possibly know whether an operation blocks or not, then it cannot "cooperate."
> As long as all the functions you call are suspendable, you equally have no idea which one will actually suspend.
First, this is true hypothetically but never in practice. Consider that if code really didn't care about blocking, then why not colour everything in the blocking colour? The answer is that in the coloured mode, compilation and cost of the two colours are very different.
Second, and more importantly, the reason that there are two colours is exactly to enable a cooperative style. While a "blocking" routine may or may not block, a non-blocking one never does and that is the crucial difference. With cooperative multi-tasking the default mode is that of a critical section -- there is no scheduling point unless you explicitly know in advance there might be one and where. With preemptive concurrency the default is the opposite: yielding may happen at any time unless you explicitly enter a critical section. This results in very different coding styles.
Anyway, we're arguing over definitions, so you may want to consult Wikipedia's definitions [1] [2].
[1]: https://en.wikipedia.org/wiki/Cooperative_multitasking
[2]: https://en.wikipedia.org/wiki/Preemption_(computing)#PREEMPT...