O'Reilly logo

Patterns for Parallel Software Design by Jorge Luis Ortega-Arjona

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.3. 5.3 Monitor

A monitor is a synchronization mechanism based on the concept of an object that encapsulates shared variables. Inside the monitor, shared variables are tagged as private resources, so the only way to manipulate them is to call on methods of the interface that operate over the shared variables. This is therefore the only way to exchange data among two or more concurrent, parallel or distributed software components executing on a shared memory parallel platform. Mutual exclusion among them is implicit and guaranteed by the compiler, allowing only one software component to be active at a time inside the monitor – that is, executing one of the methods. No execution order can be assumed [Hoa74] [Bri75] [And91] [Bac93] [Har98] [HX98] [And00].

5.3.1. Example

The Java programming language can create and execute threads on the same processor or on different processors. To allow communications among threads, Java specifies the synchronized modifier. To implement a monitor as an object in Java, the synchronized modifier is used for all methods of a class in which only one thread should be executing at a time. These methods are normally declared as public and modify shared variables declared as private inside the monitor. The methods could also be declared as private, if public access to the monitor consists of calls to several of these synchronized methods. [Har98] [And00] [MSM04].

The current example describes the development of a synchronization mechanism based on the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required