... | ... | @@ -73,6 +73,9 @@ Given an I/O-performing computation `newSCont` returns a reference to an SCont w |
|
|
Performing the body of switch atomically in a transaction avoids the nasty race conditions usually seen in multicore runtimes where one-shot continuations are used for modelling schedulers. In such systems, there are often cases where before the switch primitive has had a chance to return, another processor picks up the current continuation (appended to the scheduler) and tries to switch to it. It becomes necessary to go for complicated solutions such as releasing the scheduler locks after the target thread resumes execution to prevent races. In our case, PTM eliminates the need for such a mechanism - the other processor would not be able to access the current SCont, unless the transaction has committed and control has switched to the target SCont.
|
|
|
|
|
|
|
|
|
Primitive `getCurrentSCont` returns a reference to the current SCont under PTM. Primitive `switchTo` commits the current PTM transaction and switches to the given SCont. As we will see, these two primitives are necessary for [abstracting the scheduler](lightweight-concurrency#).
|
|
|
|
|
|
|
|
|
Of course, care must be taken to ensure that the control does not switch to an SCont that is either running or completed.
|
|
|
|
|
|
### Capabilities and Tasks
|
... | ... | |