Twilight is a C++ thread pool manager and task executor, designed for efficient task management in multi-threaded applications. The project leverages Bazel as a build system and Google Test for unit testing.
- Thread Pool Manager: Allows for dynamic task management with a configurable number of worker threads.
- Task Executor: Encapsulates tasks for flexible execution within the thread pool.
- Logging Utility: Provides basic logging for information, warnings, and errors.
- Unit Tests: Includes tests for the
ThreadPoolManager
andTaskExecutor
classes using Google Test.
Twilight/
├── WORKSPACE # Bazel workspace file
├── BUILD # Main build configuration
├── src/
│ ├── BUILD # Build rules for core library
│ ├── main.cpp # Main entry point
│ ├── thread_pool_manager.h/cpp # Thread pool manager implementation
│ ├── task_executor.h/cpp # Task executor implementation
│ └── utils/
│ ├── BUILD # Build rules for utilities
│ ├── logging.h/cpp # Simple logging utility
└── tests/
├── BUILD # Build rules for tests
├── thread_pool_manager_test.cpp # Tests for ThreadPoolManager
└── task_executor_test.cpp # Tests for TaskExecutor
- Bazel: Install Bazel to build and test the project.
- Google Test: Integrated as an external dependency; no need for separate installation.
git clone https://github.com/your-username/Twilight.git
cd Twilight
To compile the main application:
bazel build //src:thread_pool_manager_app
Execute the application with:
bazel run //src:thread_pool_manager_app
Run all tests to verify functionality:
bazel test //tests:all
The main entry point initializes the ThreadPoolManager
with a specific number of threads and enqueues tasks for execution. Here’s a basic usage example:
#include "thread_pool_manager.h"
int main() {
ThreadPoolManager manager(4, 8); // Initialize with 4 threads, can scale up to 8
manager.enqueueTask([]() { std::cout << "Task 1 running.\n"; });
manager.enqueueTask([]() { std::cout << "Task 2 running.\n"; });
manager.shutdown();
return 0;
}
To add a new task, use enqueueTask
on the ThreadPoolManager
instance:
manager.enqueueTask([]() { /* Task Code */ });
A basic logging utility (Logger
) is available and supports INFO
, WARNING
, and ERROR
levels:
Logger::log("Starting thread pool", INFO);
Logger::log("Task execution failed", ERROR);
Contributions are welcome! Please open an issue or submit a pull request for improvements or feature requests.
This project is licensed under the MIT License.