-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race conditions in thunk evaluation #867
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
robdockins
commented
Aug 21, 2020
robdockins
commented
Aug 21, 2020
Link to related issue: #856 |
@jared-w, the failures on Ubuntu seem related to the CVC4 installation. Did something on those configurations change recently? |
brianhuffman
approved these changes
Sep 1, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me; just needs a bit more documentation, especially about ThunkState
.
Thunk state is now controlled using transational memory variables instead of IORefs, and the thunk likecycle is made more explicit in the relevant datatypes. Threads will now properly block and wait when forcing a thunk that is already under evaluation by a different thread. Hopefully, using optimistic concurrency (transactional memory) will help reduce concurrency contention. The reworked lifecycle datastructures hopefully will release closures related to evaluation faster, which should reduce memory pressure somewhat. Fixes #856
Instead of making the `Eval` monad a reader that carries around the EvalOpts, pass it directly into the primitives table, which pipes it directly to the one place those options are needed. Hopefully, this will reduce closure allocations in the evaluation monad, and it also just generally simplifies things. Note, we need to be careful to instantiate the `primTable` values only as often as needed. The What4 and Concrete primitive tables now take arguments, which means they are not CAFs. As a result, they need to be let-bound someplace fairly global so that we don't recompute the map every time we look up a primitive. Hence, I have removed the helper `evalPrim` functions, and forced call sites instead to implement the map lookups.
This should help prevent redundant thunking, as we can recognize when a value is already thunked. In addition, use the already-existing thunk mechanism to implement `parmap` sparks.
brianhuffman
pushed a commit
to GaloisInc/saw-core
that referenced
this pull request
Sep 11, 2020
This updates cryptol-saw-core to work with commit GaloisInc/cryptol@0000ffbef6, adapting to PRs GaloisInc/cryptol#866 and GaloisInc/cryptol#867.
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With the addition of
parmap
, it became possible to observe race conditions in the thunk evaluation lifecycle. This PR reworks the evaluation monad so that threads will properly block and wait if they attempt to force a thunk that is already under evaluation by a different thread and uses transactional variables to ensure proper synchronization.