lecture6 - Synchronization Communicating Processes Despite...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Synchronization Communicating Processes Despite process abstraction, different computations (processes) sometimes want to communicate. Communication can increase the modularity and robustness of programs (one process for each action, the application can continue if one of the subprocesses fails), and is sometimes an end unto itself. Agood example of both uses of interprocess communication (IPC) is a web server .Modularity is increased by having a separate copyofthe server answer each query (the queries are passes from the master browser to a sub browser by IPC). The reason for the server to exist at all is to communicate between a web browser process on one computer with the server on this one. Lots of seminal work in synchronization was done in a shared memory model, which is the one we’ll start with. •W ehav e several processes timesharing the same single CPU. 1 •S cheduling is preemptive ;between any2instructions the running process may be interrupted and context switched for another. •T he processes all have access to a shared are of memory where one process can change a vari- able that can be seen by all other processes. Race Conditions An atomic action is an indivisible action - an action taken by a process than cannot be interrputed by acontext switch. When accesses to a shared variable are not atomic, call it a race condition. Consider the following simple example: shared int x =3; process_1 () { x=x+1; print x; } process_2 () { print x; } Note that although x= x + 1 looks likeone statement, it probably compiles into at least 2 and probably three machine instructions. Alikely translation is: LOAD r1 x ADD r1+1 r1 STORE r1 x Because of this, depending on when context switches occur ,any o fthe following sets of output and final values in x are possible: 1 This is called multiprogramming or multitasking. Multiprocessing refers to the contition in which many
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/28/2008 for the course CS 402 taught by Professor Tedfaber during the Spring '05 term at USC.

Page1 / 4

lecture6 - Synchronization Communicating Processes Despite...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online