Skip to content

Latest commit

 

History

History
15 lines (10 loc) · 615 Bytes

PH_P002.md

File metadata and controls

15 lines (10 loc) · 615 Bytes

PH_P002 - Monitor.Wait without Conditional Loop

Problem

The invocation of Monitor.Wait(...) is not enclosed by a while loop. However, code that uses this method usually waits for a particular state. It becomes more problematic when using it in conjunction with Monitor.PulseAll(...). Since it is not possible to specify which thread to notify, it may notify threads that wait for a different state.

Solution

Enclose the Monitor.Wait(...) invocation with a while loop that loops as long as the expected state has not been satisfied.

while(!isReady) {
    Monitor.Wait(syncObject);
}