- There are a number of tasks
Tasksare the samenumber of task queues as CPUs- A
workerhas a task queue - A worker
pushs/popstasks from its own task queue - A worker takes tasks from other workers
Pop/pushaccesses thebottom of task queues- Take accesses the
top of task queues
-
Task queue is implemented as
unbound circular arraywhich doesn't have start and end points and expands when the size is less than the number of tasks. -
There are already some implementation of Lock-free Work-stealing Deque. But one written in C is not so common. Unlike some languages like Java, the support of
volatilevariable is limited in C. This implementation covers it by using memory barriers. -
This uses
compare-and-swap (CAS) instructioninstead ofmutex lock.
Compile the deque source.
makeTo test the unit test of deque, just type
make TEST_gsoc_taskqueueYou can see the number of CPUs used in test and calculation time by
./test_gsoc_taskqueue > /dev/nullIf you also want to test circular array, type
make TEST_gsoc_task_circular_array Note that it will fail if you use 32-bit CPUs. Or if you want to test all of them,
make testyou can clean the directory.
make clean