MCPcopy Create free account
hub / github.com/Extra-Creativity/Modern-Cpp-Basics / Database

Class Database

13-Multithreading/code/shared_mutex.cpp:9–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7using namespace std::literals;
8
9class Database
10{
11public:
12 int Read() {
13 std::shared_lock sharedLock{ mutex_ };
14 std::this_thread::sleep_for(100ms); // Assuming we need 100ms to read
15 return data_;
16 }
17
18 void Write(int d) {
19 std::lock_guard exclusiveLock{ mutex_ };
20 std::this_thread::sleep_for(300ms); // Assuming we need 300ms to write.
21 data_ = d;
22 }
23private:
24 std::shared_mutex mutex_;
25 int data_ = 0;
26};
27
28int main()
29{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected