|
STTNet
|
Fixed-size worker thread pool. More...
#include <sttnet_English.h>
Public Member Functions | |
| WorkerPool (size_t n) | |
| Constructor, creates a specified number of worker threads. More... | |
| ~WorkerPool () | |
| destructor More... | |
| void | submit (Task task) |
| Submit a task to the thread pool. More... | |
| void | stop () |
| Stop the thread pool and wait for all threads to exit. More... | |
Fixed-size worker thread pool.
WorkerPool Internally, it maintains a task queue and several worker threads. Each worker thread takes a task from the queue and executes it in a loop.
|
inlineexplicit |
Constructor, creates a specified number of worker threads.
| n | Number of worker threads |
Once constructed, all threads start immediately and enter a waiting state.
|
inline |
destructor
stop() is automatically called during destruction. Ensure all threads exit and are correctly joined.
|
inline |
Stop the thread pool and wait for all threads to exit.
After calling:
This function can be called repeatedly safely.
|
inline |
Submit a task to the thread pool.
| task | Callable objects, with the function signature void() |
The task is placed in an internal queue and executed asynchronously by a worker thread.
1.8.5