This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
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.
This PR adds two different ordering strategies to the deque: FIFO and LIFO. The strategy is chosen at construction time. There are two deque constructors:
FIFO is intended to be used by Tokio and LIFO is for Rayon. The FIFO variant doesn't execute any fences.
I've tried running benchmarks on Rayon's test suite and didn't find any significant differences between this PR and the current master branch.
The LIFO variant is the same as our current Chase-Lev implementation, while FIFO is slightly tweaked
CircBuf
. I've fixed a few bugs inCircBuf
, cleaned up the code, and conservatively added a bit stronger memory orderings where I found them dubious. This time correctness is the primary concern, but we can revisit those orderings later to squeeze out more performance.In a future PR we can also add methods for batched stealing (steal half), as explained in #11.
Another thing we should consider adding later is workers that can be shared among multiple threads. In addition to thread-local deques, schedulers usually also have a special global deque, where tasks without an associated worker thread go into (
rayon::spawn
pushes tasks into the global deque). Rayon currently usesMutex<Worker<T>>
andStealer<T>
for the global deque. The mutex aroundWorker<T>
is unfortunate so we should ideally add a variant of deque that supports push and pop from multiple threads without mutexes. Such a deque would probably be implemented as a Treiber stack when using LIFO strategy and as a Michael-Scott queue when using FIFO strategy.Closes #11
cc @carllerche