In Java you can wait on every object, so this kind of scenario is possible to program:
Thread A waits on object a
Thread B waits on object b
Thread C notifys on a
Thread A notifys on b
if i use C#’s Monitor, it seems to me that Thread C could only wake b up (or b and a), then how do i make such a scenario possible?
You seem to be thinking that because the C# synchronization functions are members of the
Monitorclass, that you need a specialMonitorinstance to use them, in contrast to Java where they are members of thejava.lang.Objectclass and available for all objects.Quite the opposite. There are no
Monitorinstances at all. In C#, the functions are static methods, and still work on any object. The only reason for theMonitorclass is to preventSystem.Objectfrom being cluttered with extra members (which would show up in Intellisense suggestion lists, etc).However, I find that code using
Pulseusually has hidden race conditions. There are better ways to synchronize between threads that make writing reliable code easier.