Back to Site
Loading...
Searching...
No Matches
threadmanager.h
Go to the documentation of this file.
1#ifndef THREADMANAGER_H
2#define THREADMANAGER_H
3
4#include <thread>
5#include <vector>
6#include <mutex>
7#include <condition_variable>
8#include <atomic>
9#include "logger.h"
10
11namespace librats {
12
17public:
19 virtual ~ThreadManager();
20
21 // Add a new managed thread with optional name for debugging
22 void add_managed_thread(std::thread&& t, const std::string& name = "unnamed");
23
24 // Clean up finished threads (non-blocking)
26
27 // Signal shutdown to all threads
29
30 // Wait for all active threads to finish (blocking)
32
33 // Get count of active threads
35
36protected:
37 // Notify waiting threads of shutdown
39
40 // Condition variable for shutdown coordination
41 std::condition_variable shutdown_cv_;
42 std::mutex shutdown_mutex_;
43
44private:
45 mutable std::mutex active_threads_mutex_;
46 std::vector<std::thread> active_threads_;
47 std::atomic<bool> shutdown_requested_{false};
48};
49
50} // namespace librats
51
52#endif // THREADMANAGER_H
53
ThreadManager - Manages background threads with graceful shutdown.
void add_managed_thread(std::thread &&t, const std::string &name="unnamed")
size_t get_active_thread_count() const
std::condition_variable shutdown_cv_