multithreading - How does mutex or semaphore wake up processes? -


i read mutexes , semaphores maintain list of waiting processes , wake them when current thread completes critical section. how mutexes , semaphores that? doesn't interfere process scheduler decisions?

the waiting , waking typically done in cooperation scheduler. mutex implementation forces specific 1 of waiting threads wake typically considered poor implementation.

instead, mutex or semaphore notify scheduler thread waiting, , take off "ready run" list. then, when mutex unlocked or semaphore signalled, implementation either

  1. ask scheduler wake 1 of waiting threads @ scheduler's discretion, or

  2. notify scheduler waiting threads ready run, , have logic on waiting threads first 1 woken scheduler go sleep again.

the former preferred implementation choice, not available. second dubbed "thundering herd" approach: if there 1000 threads waiting 1000 woken (a big thundering herd of threads), 999 go sleep. wasteful of cpu resources, , implementations avoid possible.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -