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.2. 5.2 Critical Region

A critical region is a synchronization mechanism that allows two or more concurrent, parallel or distributed software components executing on a shared memory parallel platform to access code regions while guaranteeing mutual exclusion among them. Shared variables are grouped into named regions and tagged as private resources. Software components are not allowed to enter a critical region when another software component is active in any associated critical region. Conditional synchronization is performed by guards. When a software component attempts to enter a critical region, it evaluates the guard (under mutual exclusion). If the guard evaluates to false, the software component is suspended or delayed. No access order can be assumed [Bri72] [Hoa72] [And91] [Bac93].

5.2.1. Example

OpenMP is an application program interface (API) specified as library extensions for C, Fortran and C++, used to direct multithreaded, shared memory parallelism. It is a portable, scalable model for developing parallel software systems on a wide range of parallel programming platforms [OpenMP] [HX98] [And00] [MSM04] [CJV+07].

For this example, a synchronization mechanism based on the Critical Region idiom is to be developed for the channel component of the Shared Variable Channel pattern described in Section 4.5, in which the structure of the solution was presented making use of semaphores in a Java-like code. Another solution is shown here, making use of critical regions in ...

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