Skip to content

Lockless work stealing deque written in C. This is implemented after Chapter 16 of "The Art of Multiprocessor Programming."

Notifications You must be signed in to change notification settings

paranlee/lockless-work-stealing-deque-in-c

 
 

Repository files navigation

Lockless Work stealing Deque written in C.

  • There are a number of tasks
  • Tasks are the same number of task queues as CPUs
  • A worker has a task queue
  • A worker pushs/pops tasks from its own task queue
  • A worker takes tasks from other workers
  • Pop/push accesses the bottom of task queues
  • Take accesses the top of task queues

Features

  • Task queue is implemented as unbound circular array which 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 volatile variable is limited in C. This implementation covers it by using memory barriers.

  • This uses compare-and-swap (CAS) instruction instead of mutex lock.

Compile

Compile the deque source.

make

Test

To test the unit test of deque, just type

make TEST_gsoc_taskqueue

You can see the number of CPUs used in test and calculation time by

./test_gsoc_taskqueue > /dev/null

If 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 test

you can clean the directory.

make clean

Reference

  1. The Art of Multiprocessor Programming. Maurice Herlihy, Nir Shavit / Morgan Kaufmann
  2. Dynamic Circular Work-Stealing Deque. David Chase, Yossi Lev / Sun Microsystems
  3. laysakura's blog
  4. laysakura's project in Google Summer of Code 2011
  5. laysakura's twitter

About

Lockless work stealing deque written in C. This is implemented after Chapter 16 of "The Art of Multiprocessor Programming."

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 81.1%
  • Makefile 18.9%