Skip to content

Commit 7222929

Browse files
committed
Add Scheduler class structure with data members and constructor declaration
1 parent 0a8f9b2 commit 7222929

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

.vscode/c_cpp_properties.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

main.exe

121 KB
Binary file not shown.

src/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "scheduler.hpp"
2+
#include <iostream>
3+
4+
int main() {
5+
6+
std::cout << "Hello, world!\n";
7+
8+
return 0;
9+
}

src/scheduler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "scheduler.hpp"

src/scheduler.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

0 commit comments

Comments
 (0)