[prelude][core][stm] fix issue with preemption in nested async computations #927
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #925
The issue is more generic than the use with STM. Kyo's kernel uses a safepoint mechanism to preempt execution on any step of a computation.
kyo-core
extends this mechanism by setting the safepoint interceptor to the current fiber to handle preemption. For example, if the fiber is interrupted, the next safepoint will trigger preemption to stop the computation and clear finalizers. The other possibility is the scheduler itself triggering preemption due to the fiber taking more than the configured time slice (10ms by default) so it can return to the execution queue to provide fairness.The cause of the bug is the interceptor propagating to nested async computations. This PR fixes
Safepoint.eval
, which is called from the pending type'seval
, to clear the interceptor since theeval
operation itself can't be delayed and has to return a concrete value. Even if the outer async computation is preempted, the nested one needs to execute to completion.