Fix race condition and improve threadpool throughput.
1) Use an explicit mark on tasks to indicate which can have the task_commit_head and task_release_head counters advance over them. The mark must be equal to the ring buffer's cell offset to commit, or ~ the offset to release, so the value will be properly initialized to avoid false positives every loop around the ring buffer. Once a task is ready to commit/release, the counter is advanced as far as marks will allow. 2) Copy a task onto the call stack and release it, rather than keeping it in the queue while the callback executes. This improves throughput. 3) Change the edge trigger for switching worker threads between their asleep and awake states -- rather than marking a thread as asleep as soon as it fails to receive work in its awake state loop, wait to change it until it has failed to receive work twice (delay > 1). This substantially improves the queue throughput, changing the no-op benchmark's throughput from ~100 k/sec to ~5 m/sec. 4) Add several asserts throughout.
Loading
Please sign in to comment