-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds basic support for multi-threaded evaluation. Currently, only "nix search" uses this to evaluate packages in parallel. The implementation is based on Harris et al., "Haskell on a Shared-Memory Multiprocessor" (Haskell Workshop '05) (sans the blackholing for now), which describes letting threads evaluate the same thunk in parallel without locking. Since we're in a purely functionaly language, this may lead to work duplication (if two thread hit the same thunk concurrently), but is semantically safe. We just need to ensure that thunk overwriting doesn't cause problems. Thus, the "thunk" and "app" cases of the Value union are now stored separately so that they're never overwritten. This does increase memory consumption by 16 bytes per value, but it might be possible to optimize this a bit. Another worry is garbage collection effectiveness. Probably the collector will need to be taught to ignore "thunk" and "app" for non-thunk values. Similarly, the "with" attribute set is now stored in a separate field of Env, rather than in values[0], to account for the case where two threads evaluate the "with" set concurrently. There are probably still quite a few races like this one in elemAt: state.forceValue(*list.listElems()[n]); v = *list.listElems()[n]; This is now unsafe, because there is a slight possibility ‘list’ is overwritten by another thread (by a semantically equivalent value), so that ‘list.listElems()[n]’ no longer refers to the value forced in the first line. So we now need to write: auto & v2 = *list.listElems()[n]; state.forceValue(v2); v = v2; Also, a lot of code updates thunks like this: v.type = tInt; v.int = 123; This is now unsafe; it should be the other way around, with some memory ordering to prevent the compiler from swapping them back. I worked around this for now by having forceValue() use a temporary value for the thunk evaluation result.
- Loading branch information
Showing
5 changed files
with
51 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
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
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