Skip to content

sajeruk/ThreadPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThreadPool

Simple c++ thread pool inspired by https://github.com/progschj/ThreadPool Capabilities

  • Fixed-size thread pool
  • Fair non-priority task queue
  • Improvement over base: does not rely on system notify queue
Small Description - In general, it is just a code of progschj/ThreadPool with task notification improvement
In previous version you could face a problem, while having lots of heavy tasks and lots of quick task producers
Each task added to task queue produced cv.notify_one(), which added new notification directly to system queue. Modified version just uses task queue for storing tasks, ant there is one more background process ManageThread, which efficiently manages notifications. So, you can have maximum of O(THREAD_COUNT) notifications in system queue Tests - I didn't test it quite well, however, [test.cpp](test/test.cpp) provides example, when ThreadPool shows it's best in comparasion with threads spawning Compilation - Supports CMake and simple make cmake && make or just make -f Makefile.in Examples - For exaples just see [test.cpp](test/test.cpp)
Basic usage: ```c++ // create thread pool with 4 threads pool::ThreadPool tp(4); // add task to thread pool auto res = tp.AddTask([]() -> int { /* some stuff */ return rand(); }; // show result std::cout << res.get() << std::endl; ```

About

Simple c++ thread pool inspired by https://github.com/progschj/ThreadPool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published