操作系统课件ChapterIPC
Contents of this lecture 2.3 Interprocess Communication Race Conditions Critical Region and Mutual Exclusion Mutual Exclusion Using Busy Waiting Sleep and Wakeup Semaphores Monitors Message Passing 2.5 Classic IPC Problems Summary 2.3 Interprocess Communication 2.5 Classic IPC Problems Summary Inter-Process Communication Communication Pass information to each other UNIX pipe (special file) e.g. $ sort file1|grep scut Mutual Exclusion Keep each other’s hair Synchronization Proper sequencing The last one also applies to threads A Simple Example (1) A function to withdraw money from a bank account: int withdraw (account, amount) { balance = get_balance (account); balance = balance - amount; put_balance (account, balance); return balance; } Now suppose that you and your roommate share a bank account with a balance of ¥1500 (this is not necessarily a good idea...) What happens if you both go to separate ATM machines, and simultaneously withdraw ¥ 100 from the account? A Simple Example (2) We represent the situation by creating a separate thread for each ATM user doing a withdrawal Both threads run on the same bank server system What’s the problem with this? What are the possible balance values after each thread runs? A Simple Example (3) The execution of the two threads can be interleaved Assume preemptive scheduling Each thread can context switch after each instruction We need to worry about the worst-case scenario! What’s the account balance after this sequence? And whos happier, the bank or you??? A Simple Example (4) Which resources are shared? Local variables in a function are not shared They exist on the stack, and each thread has its own stack Global variables are shared Stored in static data portion of the address space Accessible by any thread Dynamically allocated data is shared Stored in the heap, accessible by any thread A Simple Example (5) The execution of the two threads can be interleaved Assume preemptive sched
您可能关注的文档
最近下载
- 2024—2025学年度安徽省合肥市第六中学高一下学期期末考试历史试题(含答案).docx VIP
- 4.国内高空观测数据BUFR编码格式(V1.0).doc VIP
- 兽药企业安全生产培训PPT.ppt VIP
- 输变电工程建设标准强制性条文10248-2016_部分2.pdf VIP
- 2025年高考(北京卷)物理真题及答案.doc VIP
- 2026人教版五年级上册语文期末考试3套试卷(打印版含答案解析).pdf
- 承插型盘扣式钢管模板支架施工验收记录表.doc VIP
- 长郡初三期末物理试卷及答案.doc VIP
- 湖北省武汉市江汉区2024-2025学年八年级上学期1月期末道德与法治试卷.docx VIP
- 黄冈达标卷数学2年级下(单元测+期中+期末).docx VIP
原创力文档

文档评论(0)