OperatingSystemsCh5Process Communication & Synchronization-Part 21
Operating Systems Ch5 Process Communication & Synchronization -Part 2 1
IPC problem: Race condition2
2 P P P IPC problem: Race condition
Evil source:the shared objectsdataProcessProcessPipe is implemented with thethought that there may beread()write()more than oneprocessaccessing it"at the same time"For shared memory and files,Filestructureinthekernelconcurrent access may yieldunpredictable outcomesHard Disk3
Evil source: the shared objects • Pipe is implemented with the thought that there may be more than one process accessing it “at the same time” • For shared memory and files, concurrent access may yield unpredictable outcomes 3 Process Process read() write() File structure in the kernel data Hard Disk
Understanding the problem..The ScenarioHigh-levellanguageforProgramAattach to the shared memory X;12Shared memoryadd 1o to X;3exit;Value= 10High-levellanguageforProgramBminus 10;add 10;1attach to the sharedmemoryX;2minus10 to X;ProcessBProcessA3exit;It maybe10,0or20,canyoubelieve it?Guess whatthefinal result shouldbe?4
Understanding the problem. 4 Process A Process B Shared memory Value = 10 add 10; minus 10; The Scenario High-level language for Program A 1 attach to the shared memory X; 2 add 10 to X; 3 exit; Guess what the final result should be? High-level language for Program B 1 attach to the shared memory X; 2 minus 10 to X; 3 exit; It may be 10, 0 or 20, can you believe it?
Understanding the problem..The ScenarioHigh-levellanguageforProgramA1attachtotheshared memory X;2add10toX;Shared memory3exit;Value=10High-levellanguageforProgramBminus 10;add 10;1attach totheshared memory X:2minus10toX;ProcessAProcessB3exit;Remember the flow of executing a program and the system hierarchy?5
Understanding the problem. 5 Process A Process B Shared memory Value = 10 add 10; minus 10; The Scenario High-level language for Program A 1 attach to the shared memory X; 2 add 10 to X; 3 exit; High-level language for Program B 1 attach to the shared memory X; 2 minus 10 to X; 3 exit; Remember the flow of executing a program and the system hierarchy?