File tree Expand file tree Collapse file tree 5 files changed +64
-0
lines changed
Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "configurations" : [
3+ {
4+ "name" : " Win32" ,
5+ "includePath" : [
6+ " ${workspaceFolder}/**"
7+ ],
8+ "defines" : [
9+ " _DEBUG" ,
10+ " UNICODE" ,
11+ " _UNICODE"
12+ ],
13+ "windowsSdkVersion" : " 10.0.22000.0" ,
14+ "compilerPath" : " cl.exe" ,
15+ "cStandard" : " c17" ,
16+ "cppStandard" : " c++23" ,
17+ "intelliSenseMode" : " windows-msvc-x64"
18+ }
19+ ],
20+ "version" : 4
21+ }
Original file line number Diff line number Diff line change 1+ #include " scheduler.hpp"
2+ #include < iostream>
3+
4+ int main () {
5+
6+ std::cout << " Hello, world!\n " ;
7+
8+ return 0 ;
9+ }
Original file line number Diff line number Diff line change 1+ #include " scheduler.hpp"
Original file line number Diff line number Diff line change 1+ #ifndef SCHEDULER_HPP
2+ #define SCHEDULER_HPP
3+
4+ #include < queue>
5+ #include < vector>
6+ #include < thread>
7+ #include < mutex>
8+ #include < condition_variable>
9+ #include < atomic>
10+ #include < functional>
11+
12+ class Scheduler {
13+ private:
14+ // Queue of pending tasks waiting to be executed by worker threads
15+ std::queue<std::function<void ()>> task_queue_;
16+
17+ // Pool of worker threads that execute tasks from the queue
18+ std::vector<std::jthread> workers_;
19+
20+ // Mutex to protect the task queue from concurrent access
21+ std::mutex queue_mutex_;
22+
23+ // Condition variable to wake up worker threads when tasks are available
24+ std::condition_variable condition_;
25+
26+ // Atomic flag to signal all worker threads to stop (for graceful shutdown)
27+ std::atomic<bool > shutdown_;
28+ public:
29+ // Constructor: Creates a thread pool with 'num_threads' worker threads
30+ explicit Scheduler (size_t num_threads);
31+ };
32+
33+ #endif
You can’t perform that action at this time.
0 commit comments