Advertisement
mohsentux

lack of multithreading features in win32 with pthreads

May 11th, 2022
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. // mutex.cpp from the book "Concurrency with Modern C++ by Rainer Grimm"
  2. // a bad code that works incorrectly under win32 -- it should completely lock one
  3. // of the cores and put it to 100% (reserving it poorly) but it only works badly as
  4. // expected under linux distros such as Ubuntu LTS that I tested it on.
  5.  
  6. #include <mutex>
  7. #include <thread>
  8.  
  9. std::mutex mut;
  10.  
  11. void workOnResource(){
  12. mut.lock();
  13. std::this_thread::sleep_for(std::chrono::milliseconds(5000));
  14. mut.unlock();
  15. }
  16.  
  17. int main(){
  18.  
  19. std::thread t(workOnResource);
  20. std::thread t2(workOnResource);
  21.  
  22. t.join();
  23. t2.join();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement