- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Modern Operating Systems-Chapter 2 – Interprocess
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
文档评论(0)