四川丹甫制冷压缩机股份有限公司招.4.pptVIP

  • 1
  • 0
  • 约8.86千字
  • 约 29页
  • 2018-03-29 发布于广东
  • 举报

四川丹甫制冷压缩机股份有限公司招.4.ppt

四川丹甫制冷压缩机股份有限公司招.4

Outline for Today Objective: To continue talking about the critical section problem and get more practice thinking about possible interleavings. Start talking about synchronization primitives. Introduce other “classic” concurrency problems Administrative details: Look on the web for TAs’ office hours or check newsgroup for UTAs’ office hours for assignment 1. On collecting problem sets… Semaphores Well-known synchronization abstraction Defined as a non-negative integer with two atomic operations P(s) - [wait until s 0; s--] V(s) - [s++] The atomicity and the waiting can be implemented by either busywaiting or blocking solutions. Semaphore Usage Binary semaphores can provide mutual exclusion (solution of critical section problem) Counting semaphores can represent a resource with multiple instances (e.g. solving producer/consumer problem) Signaling events (persistent events that stay relevant even if nobody listening right now) Producer / Consumer Producer: while(whatever) { locally generate item fill empty buffer with item } Consumer: while(whatever) { get item from full buffer use item } Producer / Consumer Producer: while(whatever) { locally generate item fill empty buffer with item } Consumer: while(whatever) { get item from full buffer use item } Tweedledum and Tweedledee Separate threads executing their respective procedures. The idea to cause them to forever take turns exchanging insults through the shared variable X in strict alternation. The Sleep() and Wakeup() routines operate as follows: Sleep blocks the calling thread, Wakeup unblocks a specific thread if that thread is blocked, otherwise its behavior is unpredictable The code shown above exhibits a well-known synchronization flaw. Outline a scenario in which this code would fail, and the outcome of that scenario void Tweedledum() { while(1) { Sleep(); x = Quarrel(x); Wakeup(Tweedledee); } } void Tw

文档评论(0)

1亿VIP精品文档

相关文档