- 17
- 0
- 约3.32万字
- 约 122页
- 2016-12-26 发布于贵州
- 举报
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
您可能关注的文档
最近下载
- 商务星球版2025-2026学年七年级下册地理教学工作计划(及进度表).docx
- TCL 移动空调KYR-35 KY使用说明书.pdf
- 工业机器人离线编程与仿真 教案 项目1--4 仿真软件的安装与工作站的构建---仿真软件的应用.docx VIP
- 人文艺术欣赏ppt课件(优质ppt).pptx VIP
- 伤口评估与护理记录PPT课件.pptx
- 骨科手术高龄患者并发症及相关护理措施-来源:现代养生(下半月版)(第2018001期)-河北省医疗气功医院.pdf VIP
- 小学一二年级全册体育教案.pdf VIP
- 大数据环境下网络安全问题探讨.doc VIP
- 论司法确认程序审查规则检视与优化.docx VIP
- 2022年中国社会科学院法律史考博真题、考博参考书,考博资料,难度分析.pdf VIP
原创力文档

文档评论(0)