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.
Sort-of fixes #14 by scrapping
JobPool
withJob
structs and instead having a lightConcurrentQueue
with managedJob
classes.(This can be merged after #21 is merged.)
The new
Job
class is a class that is thread safe by nature, where all of its operations when used properly can be used without any locks. It maintains a personal lock (so this isn't lock-free) but that should reduce the chance of lock-contention from "almost guaranteed" to "almost never." I think this is as close to a lock-free solution as we can get at the moment, but it should also make implementing a lock-free solution ten million times easier by constraining locks into one API.The only time lock contention should happen is:
3 is the only case where lock contention may occur from the scheduler as overhead, and not from random user Complete() calls. But I don't think there's a way to prevent that, and it seems rare.
I expected it would be faster, but it is WAY faster! Just check out the random graph benchmarks:
Old:
New:
The rest of the benchmarks have similar gains.