-
Notifications
You must be signed in to change notification settings - Fork 0
synchronisation technique
sharmasadhna edited this page May 9, 2022
·
1 revision
NOTE: Both are kernel resources so obvious overheads
signalling mechanism: any higher priority thread can also release semaphore and take lock, thus no ownership
- binary semaphore : 0 (unlocked)/1 (locked)
- counting semaphore: 0 (unlocked)/ use and inc value, release dec value
In C++ 20 onwards
- locking mechanism: lock mutex before critical section and then release,
- Ownership: whover locked must release the mutex, no other process can unlock
In C++ --> avaoid direct taking mutex and lock/unlock: but use
- std::unique_lockstd::mutex lock (mutex_var) ---> lock the mutex, and later have to be unlocked by different API's one example condition_variable (cv.wait(mutex_var)): cv automatically releases the lock here.
- std::lock_guardstd::mutex lock (mutex_var) --> automatically releases the mutex after the block