{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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. A good example of both uses of interprocess communication (IPC) is a web server. Modularity is increased by having a separate copy of the 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. We hav e several processes timesharing the same single CPU. 1 Scheduling is preemptive; between any 2 instructions the running process may be interrupted and context switched for another. The 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 a context 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 () { x = x +1; print x; } Note that although x = x +1 looks like one statement, it probably compiles into at least 2 and probably three machine instructions. A likely translation is: LOAD r1 x ADD r1+1 r1 STORE r1 x Because of this, depending on when context switches occur, any of the following sets of output and final values in x are possible: 1 This is called multiprogramming or multitasking.
Background image of page 1

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

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

{[ snackBarMessage ]}