12.1. Critical regions in programming languages

We discussed earlier the general concept of the critical region, as that section of code where shared data is accessed. Here we show a possible implementation of the concept. A critical region construct requires syntax such as the following to be added to the high-level language:

  • declaring a data type to be shared, such as:

    shared DataType someSharedData 
    
  • a region declaration such as:

    region (someSharedData) { ....} 
    

For each shared data declaration the compiler could create a semaphore, for example crSem. Then, at the start of any critical region construct for that data it could insert a crSem.semWait() operation and a crSem.semSignal() at the end. If the Java syntax included this facility, it would ...

Get Operating Systems: Concurrent and Distributed 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.