Created
October 4, 2015 23:10
-
-
Save Preetam/80235b95f32a2a61e4fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
#include <chrono> | |
#include "rwmutex.hpp" | |
cpl::RWMutex mu; | |
int | |
main() { | |
std::thread a([]() { | |
mu.r_lock(); | |
std::cout << "Reader a" << std::endl; | |
mu.r_unlock(); | |
}); | |
std::thread b([]() { | |
mu.lock(); | |
std::cout << "Writer b" << std::endl; | |
std::this_thread::sleep_for(std::chrono::seconds(1)); | |
mu.unlock(); | |
}); | |
std::thread c([]() { | |
mu.r_lock(); | |
std::cout << "Reader c" << std::endl; | |
mu.r_unlock(); | |
}); | |
std::thread d([]() { | |
mu.r_lock(); | |
std::cout << "Reader d" << std::endl; | |
mu.r_unlock(); | |
}); | |
std::thread e([]() { | |
mu.r_lock(); | |
std::cout << "Reader e" << std::endl; | |
mu.r_unlock(); | |
}); | |
std::thread f([]() { | |
mu.lock(); | |
std::this_thread::sleep_for(std::chrono::seconds(1)); | |
std::cout << "Writer f" << std::endl; | |
mu.unlock(); | |
}); | |
a.join(); | |
b.join(); | |
c.join(); | |
d.join(); | |
e.join(); | |
f.join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment