|
ThreadSchedule 2.0.0
Modern C++ thread management library
|
This guide helps you move from v1.x to v2.0.0. It lists breaking changes first, then behavioral changes you should be aware of, and finally optional upgrades that are not required but often worthwhile.
For the authoritative list of every change, see CHANGELOG.md.
ThreadPool::submit_range and GlobalThreadPool::submit_range are removed. Use submit_batch with the same iterators.
submit_batch acquires the queue lock once for the whole range and matches the API of FastThreadPool and HighPerformancePool.
On ThreadPool and FastThreadPool, these functions now return expected<void, std::error_code> (same as HighPerformancePool already did).
They are now:
Runtime behavior is unchanged. You only need to act if you:
Statistics on the single-queue pools now includes tasks_per_second and avg_task_time, like the other pools. If you use designated initializers or memset-style initialization that assumed a smaller struct, update the initializer list.
These are now aliases; the public API is unchanged:
Only unusual code (e.g. explicit template specialization on the old type name) may need the new spelling.
add_callback now returns size_t (stable callback id for remove_callback / has_callback). Code that ignored the return value is unaffected. Code that assumed void must be updated.
shutdown() now takes an optional ShutdownPolicy (default drain, matching old behavior). Old call sites without arguments behave as before.
Destructors still shut down the pool; they use drain by default. No change required unless you want drop_pending explicitly before destruction.
Implementation is now chunked (same strategy as HighPerformancePool): the range is split into a small number of tasks instead of one task per element.
If you relied on one future per element, switch to an explicit loop with submit, or chunk manually.
ScheduledThreadPoolT dispatches due tasks with post() instead of submit(), so no std::future is created per dispatch. Your task bodies are unchanged; only internal overhead is lower.
These are not required for a successful build but match v2 design well:
| Goal | Approach |
|---|---|
| Less overhead than submit() | Use post() / try_post() when you do not need a return value or std::future. |
| Dedicated fire-and-forget pool | Use LightweightPool / LightweightPoolT<N> (SBO task buffer, no futures). |
| Non-throwing submit | Use try_submit() / try_submit_batch() and check expected. |
| Tune fast pool polling | Use ThreadPoolBase<PollingWait<Ms>> or keep FastThreadPool (10 ms default). |
| Tune HP deque size | HighPerformancePool(threads, deque_capacity). |
| Fix global pool size early | GlobalPool<...>::init(n) before first instance(). |
| Workers in registry | Pass register_workers = true to pool constructors. |