Semaphores are simple and powerful, but it can be difficult to design more complex interactions between
processes using semaphores. For instance, suppose a number of threads share read and write access to a file.
CHAP. 6] OPERATING SYSTEMS 107
Perhaps the designer wants to avoid the situation where a writer changes something while a reader is reading.
It??™s fairly easy to use three semaphores to design the application so that as long as any reader is active with the
file or waiting to be active, no writer is permitted to make any changes.
On the other hand, suppose the designer wants to avoid having a writer change the file contents while
a reader is reading, but also wants to give a writer priority over waiting readers so that readers will get the latest
information. To implement this writers-first policy requires five semaphores and very careful thinking about
how to use them.
MONITORS
In the mid 1970s, researchers Hoare and Brinch Hansen proposed the monitor idea. A properly written
monitor can simplify the coordination of processes or threads. Monitors are either built into the programming
language, as with Java, or if the application language does not provide monitors, they are specially written.
Pages:
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294