Monitors

Semaphores can be very useful for solving concurrency problems, but only if programmers use them properly.

If even one process fails to abide by the proper use of semaphores, either accidentally or deliberately, then the whole system breaks down. Since concurrency problems are by definition rare events, the problematic code may easily go unnoticed and be hard to debug.

For this reason, a higher-level language construct has been developed, called monitors, which can replace the use of semaphores. In the Monitor class, all the data is private and only one function within any given Monitor object may be active at the same time. An additional restriction is that Monitor methods may only access the shared data within the monitor and any data passed to them as parameters. That is, they cannot access any data external to the monitor.

Java and C# ("C sharp"), two object-oriented langauges, offer Monitor APIs.