2

I am reading about locks and mutexes in C+11 . Currently I am familiar with two basic types of locks

1-std::lock_guard
2-std::unique_lock

I am familiar with the basic differences between the two. The first one is a simple RAII version of a mutex lock and the second one is an advanced version which supports conditional locks and deferred locking.I have read on some forums mentioning certain types of locks (I am not sure which ones they talk about) that perform a Kernel call upon locking. My question is do the locks mentioned above perform a kernel call. If so what is the point of performing a kernel call ? Does that mean if a resource is locked and kernel is aware of the state of the resource no other process will be able to access that resource. I wanted to know what happens in windows / Linux ? Are the behaviours same ?

James Franco
  • 4,516
  • 10
  • 38
  • 80
  • Yes, you can investigate the specific Linux API calls using `strace`. `std::lock_guard` is calling `arch_prctl()` and `mprotect()`. – syntagma Oct 25 '15 at 18:19
  • what about in windows ? Let me update the question – James Franco Oct 25 '15 at 18:22
  • Only a kernel call can definitely remove execution from a thread that has to wait. Whether such a call is effective depends on how long the thread is normally expected to be waiting on the synchro object. Nanoseconds wait - kernel call is an expensive overhead. 10ms wait, kernel call saves millions of execution/memory cycles that can be applied to another thread during the wait. – Martin James Oct 25 '15 at 20:20

0 Answers0