Thread Protector is a robust C++ library for protecting and monitoring multi-threaded applications. It offers automatic thread management, unresponsive thread detection, and forced termination handling.
- Automatic thread monitoring
- Heartbeat system to detect unresponsive threads
- Forced thread termination detection
- Safe thread shutdown mechanism
- C++17 or later
- CMake 3.10 or later (for building)
-
Clone the repository:
git clone https://github.com/kprprivate/Thread-Protector.git cd thread-protector
-
Create a build directory:
mkdir build && cd build
-
Run CMake and build:
cmake .. make
Here's a basic example of how to use Thread Protector:
#include "thread_protector.hpp"
void myThreadFunction(int arg, std::shared_ptr<std::atomic<bool>> status, size_t index) {
while (*status) {
// Your thread logic here
g_monitor.updateHeartbeat(index);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
int main() {
ThreadMonitor monitor;
addProtectedThread(myThreadFunction, 42);
// Main thread logic
while (monitor.monitorThreads()) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
monitor.stopAllThreads();
return 0;
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.