Cthreads: implement task queue per thread with task stealing (#528)
Cthreads classes: - Notification queue : Manages tasks: tries or forces popping and pushing tasks. - Task system : manages the notifications queues; controls which queue to pop from/push to; controls spinning on queues if necessary; manages creating/joining threads. Is a singleton. - Task group : manages synchronization on a group of tasks. Operation: - Each thread has an associated queue - Task system _tries to_ push tasks in one of the available queues. If it is unable to acquire a lock on a queue, it tries the next in a round robin fashion. After it loops all queues if it still hasn't successfully pushed the task, it spins on a single queue until lock is acquired and task is pushed. - Task system _tries to_ pop a task from the calling thread's queue. If it is unable to acquire the lock, it tries to steal the task from another thread's queue, in a round robin loop. If it is still unable to pop a task, it spins on its the calling thread's queue until the lock is acquired. - Task group keeps a counter for the number of tasks in the group which it increments/decrements when calling push/pop on the task system. The counter is used to know when all tasks in the group have been executed. Unit tests: - Basic tests to pop/push from notification_queue, task_system and task_group. - Simple tests for deadlock - Simple tests for correctness Benchmark: - Benchmarks performance for various task sizes
Showing
- arbor/threading/cthread.cpp 85 additions, 94 deletionsarbor/threading/cthread.cpp
- arbor/threading/cthread_impl.hpp 117 additions, 139 deletionsarbor/threading/cthread_impl.hpp
- test/ubench/CMakeLists.txt 1 addition, 0 deletionstest/ubench/CMakeLists.txt
- test/ubench/event_setup.cpp 1 addition, 0 deletionstest/ubench/event_setup.cpp
- test/ubench/task_system.cpp 49 additions, 0 deletionstest/ubench/task_system.cpp
- test/unit/CMakeLists.txt 1 addition, 0 deletionstest/unit/CMakeLists.txt
- test/unit/test_thread.cpp 211 additions, 0 deletionstest/unit/test_thread.cpp
Please register or sign in to comment