Skip to content

A simple C 11 Thread Pool implementation

License

Notifications You must be signed in to change notification settings

en4bz/ThreadPool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThreadPool

A simple C 11 Thread Pool implementation.

Note: The default constructor ThreadPool<POLICY> name; will create a ThreadPool with a number of worker threads equivelent to std::thread::hardware_concurrency() or in other words the same number of threads, including hyperthreads, of the underlying CPU. Should be the same value as nproc.

Now with queueing policies!

  • FIFO (default)
  • Creates a First In First Out ThreadPool, queueing submitted tasks using std::queue.
  • To create: ThreadPool<> name(numberOfThreads); or ThreadPool<FIFO> name(numberOfThreads);
  • To enqeue: enqueue(function, arguments...);
  • LIFO
  • Creates a Last In First Out ThreadPool, queueing submitted tasks using std::stack.
  • To create: ThreadPool<LIFO> name(numberOfThreads);
  • To enqeue: enqueue(function, arguments...);
  • PRIORITY
  • Creates a prioritized ThreadPool, queueing submitted tasks using std::priority_queue.
  • To create: ThreadPool<PRIORITY> name(numberOfThreads);
  • To enqeue: enqueue(priority, function, arguments...);
  • Tasks with higher (greater integer value) priorites will be dequeued before ones with lower priority.
    For example:

        ThreadPool<PRIORITY> tp;
        tp.enqueue(10, func1, args...);
        tp.enqueue(2, func2, args...);

  will cause `func1` to be dequeued before `func2` assuming that both tasks are submitted at the same time. 

About

A simple C 11 Thread Pool implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%