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
ask scheduler wake 1 of waiting threads @ scheduler's discretion, or
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
Post a Comment