I want some clarification regarding mutex and semaphore.
My question is,
- What mutex actually do when a thread tries to enter a region locked by a mutex, a. it waits for the lock to be released? or b. it goes to sleep until the lock is released. In that case how it is wake up again when the lock is released?
- Same question as 1, but in this case it is semaphore.
- Can you give me some code regarding busy waiting in pthread in C, and also a case where thread goes to sleep instead of waiting? does sleep mean it is blocked or sleeping is another kind of busy waiting?
- i want to know some programs where this situations are covered, for example some c source codes where busy waiting, blocking etc are implemented.