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 ...

Get Patterns for Parallel Software Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.