《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 5 Process Communication & Synchronization -Part 2

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?

Understanding the problem..The ScenarioHigh-levellanguageforProgramAattach to the shared memory X;12Sharedmemoryadd 1o to X;This operation3exit;is not atomicValue= 10Partial low-level languageforProgramAminus 10;add 10;1attach to the shared memory X;ProcessAProcessB2.1load memory X to register A;2.2add 1o to register A;2.3write register A to memory X3exit;Guess what? Thiscodeblockisevil!6
Understanding the problem. 6 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; Partial low-level language for Program A 1 attach to the shared memory X; . 2.1 load memory X to register A; 2.2 add 10 to register A; 2.3 write register A to memory X; . 3 exit; Guess what? This code block is evil! This operation is not atomic

Understanding the problem..Shared memory-XValue = 10State:State:RegisterRegister AAReadyValue=0Value=0Ready2.1load memory X to2.1load memory X toregister A;register A;2.22.2add 1o to register A;minus 1o from register A;2.32.3write register A towrite register A tomemory X;memory X;ProcessAProcessBThe initial setting7
Understanding the problem. 7 Process B Shared memory - X Value = 10 State: Ready Register A Value = 0 Process A State: Ready Register A Value = 0 2.1 load memory X to register A; 2.2 add 10 to register A; 2.3 write register A to memory X; 2.1 load memory X to register A; 2.2 minus 10 from register A; 2.3 write register A to memory X; The initial setting

ExecutionFlow#18
8 Execution Flow #1

Problem not yet arise..Shared memory-XValue = 10State:State:Register ARegister AValue =10RunningValue=0Ready2.1load memory X to2.1load memory Xtoregister A;register A;2.22.2minus 1o from register A;add 1o to register A;2.3write register A to2.3write register A tomemory X;memory X;ProcessAProcessBIntelCore"17ExecutionFlow#1,Step19
Problem not yet arise. 9 Process B Shared memory - X Value = 10 State: Running Register A Value = 10 Process A 2.1 load memory X to register A; 2.2 minus 10 from register A; 2.3 write register A to memory X; State: Ready Register A Value = 0 2.1 load memory X to register A; 2.2 add 10 to register A; 2.3 write register A to memory X; Execution Flow #1, Step 1 1

Problem not yet arise..Shared memory-XValue = 10State:State:Register ARegister ARunningValue=20Value=0Ready2.1load memory X to2.1load memory X toregister A;register A;2.2minus 1o from register A;2.2add 1o to register A;2.3write register A to2.3write register A tomemory X;memory X;ProcessAProcessBIntelCore"17ExecutionFlow#1,Step210
Problem not yet arise. 10 Process B Shared memory - X Value = 10 State: Running Register A Value = 20 Process A 2.1 load memory X to register A; 2.2 minus 10 from register A; 2.3 write register A to memory X; State: Ready Register A Value = 0 2.1 load memory X to register A; 2.2 add 10 to register A; 2.3 write register A to memory X; Execution Flow #1, Step 2 1 2
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 5 Process Communication & Synchronization(part1).pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 4 Threads.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 3 Process Concepts & Operations(part2)from Kernel's Perspective.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 3 Process Concepts & Operations(part1).pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 2 Operating System Structures.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 1 Overview of an Operating System.pdf
- 《计算机网络》课程教学资源(PPT课件)第六章 应用层.pptx
- 《计算机网络》课程教学资源(PPT课件)第五章 传输层.pptx
- 《计算机网络》课程教学资源(PPT课件)第四章 网络层.pptx
- 《计算机网络》课程教学资源(PPT课件)第三章 数据链路层.pptx
- 《计算机网络》课程教学资源(PPT课件)第二章 物理层.pptx
- 《计算机网络》课程教学资源(PPT课件)第一章 概述.pptx
- 《智能算法设计与应用》课程教学大纲 Intelligent Algorithm Design and Application.docx
- 《数字导航技术》课程教学资源(书籍文献)计算机视觉-马颂德.pdf
- 《C语言程序设计》课程参考文献:Programming languages — C(PDF电子书,英文版).pdf
- 《操作系统》课程教学资源(PPT课件)课程简介 Operating System.pptx
- 《操作系统》课程教学资源(PPT课件)第1章 操作系统引论.pptx
- 《操作系统》课程教学资源(PPT课件)第2章 进程的描述和控制.pptx
- 《操作系统》课程教学资源(PPT课件)第3章 处理机调度与死锁.pptx
- 《操作系统》课程教学资源(PPT课件)第5章 虚拟存储器.pptx
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 6 Process Scheduling.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 7 Memory Management part1.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 7 Memory Management part2.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 8 Mass Storage.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 9 File Systems part1.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 9 File Systems part2.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 10 Details of FAT32.pdf
- 《操作系统原理与设计 Operating System Principles and Implementation》课程教学课件(英文讲稿)Chapter 10 Details of Ext2/3 File System.pdf
- 北京工业大学:信息科学技术学院《C#程序设计基础》课程教学大纲 Fundamentals of Programming Principle and Practice in C#.pdf
- 北京工业大学:计算机学院本科课程教学大纲汇编(2024).pdf
- 揭阳职业技术学院:《计算机应用基础》课程授课教案(讲义,2025).pdf
- 《C语言程序设计》课程教学课件(PPT讲稿)第10章 对文件的输入输出.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第01章 程序设计和C语言.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第02章 算法——程序的灵魂.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第03章 最简单的C程序设计——顺序程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第04章 选择结构程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第05章 循环结构程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第06章 利用数组处理批量数据.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第07章 用函数实现模块化程序设计.pptx
- 《C语言程序设计》课程教学课件(PPT讲稿)第08章 善于利用指针.pptx
