https://github.com/jeremyko/kothreadpool
simple c++ thread pool
https://github.com/jeremyko/kothreadpool
thread thread-pool
Last synced: 6 months ago
JSON representation
simple c++ thread pool
- Host: GitHub
- URL: https://github.com/jeremyko/kothreadpool
- Owner: jeremyko
- License: mit
- Created: 2017-10-08T04:16:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-01-18T12:49:37.000Z (about 1 year ago)
- Last Synced: 2025-07-18T02:20:48.844Z (7 months ago)
- Topics: thread, thread-pool
- Language: C++
- Homepage:
- Size: 21.5 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# KoThreadPool #
### What ###
simple thread pool library for c++
### Usage ###
see sample directory
```cpp
MyClass myclass; //has member function : void MyThreadWork1(), void MyThreadWork2(int,int,int)
void MyThreadWork() ; //free function
KoThreadPool tpool;
tpool.InitThreadPool();
//tpool.InitThreadPool(4); //explicit thread worker count
tpool.SetWaitingCnt(3); //set total work count
//assign your work.
std::function temp_func1 = std::bind( &MyClass::MyThreadWork1, &myclass) ;
tpool.AssignTask(temp_func1 ) ;
std::function temp_func2 = std::bind( &MyClass::MyThreadWork2, &myclass,1,1,1) ;
tpool.AssignTask(temp_func2 ) ;
std::function temp_func3 = std::bind( &MyThreadWork ) ;
tpool.AssignTask(temp_func3 ) ;
//wait all 3 works done.
//or you can call "Terminate(true)" here to exit program.
tpool.WaitAllWorkDone(); // --> blocking call.
//At the end of the program, exit the thread pool.
tpool.Terminate(); //graceful terminate : wait until all work done
//tpool.Terminate(true); // terminate immediately
```