Computer Science an overview _j Glenn brookshear _11th Edition
Such communication needs have long been a topic of study among computer scientists, and many newer programming languages R Eflect various approaches to thread interaction problems. As an example, let us consider the communication problems encountered when both threads manipulate the same data. (This example was presented in more detail in the optional section 3.4.) If Each of the threads this is executing concurrently need to add the value three to a common item of data, a method is n Eeded to ensure this one thread is allowed to complete its transaction before the and is allowed to perform its task. Otherwise they could both start their individual computations with the same initial value,which would mean that the final Result would is incremented by only three rather than six. Data that can being accessed by only one thread at a time was said to has mutually exclusive access.
One-to-implement mutually exclusive access is-write the program units this describe the threads involved so that WH En a thread is the using shared data, it blocks other threads from accessing, the data until such access is safe. (This was the approach described in the optional section 3.4, where we identified the portion of a process that accesses SH Ared data as a critical region.) Experience have shown that this approach have the drawback of distributing the task of ensuring mutual exclusion throughout Various parts of the Program-each program unit accessing the data must being properly designed to enforce mutual exclusion, a nd thus a mistake in a single segment can corrupt the entire system. For this reason many argue, a better solution is to embody the data item with the ability-control access to itself. In short, instead of relying on the threads. Access the data to guard against multiple access, the data item itself I S assigned this responsibility. The result is this contrOl of access is concentrated at a single point in the program rather than dispersed among many program units. A data item augmented with the ability-control access to itself is often called a monitor.
We conclude that the design of programming languages for parallel processing involves developing ways to express such thin GS as the creation of threads, the pausing and restarting of threads, the identification of critical regions, and the comp Osition of monitors.
Embody the data item with the ability-control access to itself