Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // mutex.cpp from the book "Concurrency with Modern C++ by Rainer Grimm"
- // a bad code that works incorrectly under win32 -- it should completely lock one
- // of the cores and put it to 100% (reserving it poorly) but it only works badly as
- // expected under linux distros such as Ubuntu LTS that I tested it on.
- #include <mutex>
- #include <thread>
- std::mutex mut;
- void workOnResource(){
- mut.lock();
- std::this_thread::sleep_for(std::chrono::milliseconds(5000));
- mut.unlock();
- }
- int main(){
- std::thread t(workOnResource);
- std::thread t2(workOnResource);
- t.join();
- t2.join();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement