Question: 182 Chapter8 Monitors and Blocking Synchronization 1 class LockedQueue { 2 final Lock lock new ReentrantLock); final Condition notFull lock.newCondition() final Condition notEmpty - lock.newCondition;

 182 Chapter8 Monitors and Blocking Synchronization 1 class LockedQueue { 2

182 Chapter8 Monitors and Blocking Synchronization 1 class LockedQueue { 2 final Lock lock new ReentrantLock); final Condition notFull lock.newCondition() final Condition notEmpty - lock.newCondition; 5 final Tl items: 6 int tail, head, count; 7 public LockedQueue(int capacity) f 8 items (T)new object[capacity]: 10 public void enq(T x) { 11 lock.lock): 12 try I 13 while (count items.1ength) notFul1.await); items [tail] x; 14 15 16 if (Htailitems.1ength) tail 0; 18 19 20 finally l ++count; notEmpty.signa1): lock.unlock); 23 24 public T de) I 25 1ock.lockO; 26 try f 27 28 29 30 while (count 0) notEmpty.await) Tx items [head]; if (++head items.length) head 0: .-count; 32 33 notFull.signal): 34 35 finally ( 36 lock.unlock()O: return x; 38 39 Figure 8.5 The LockedQueue class: a FIFO queue using locks and condisions Thet condition fields, one to detect when the queue becomes nonempcyx it becomes nonfull. Either of these two practices would fix the bounded bighe described. Each has a small performance penalty the cost of a lost wakeup. lava provides built-in support for monitors in dre ty blocks and methods, as well as built-in wait(), not methods. (See Appendix A.) 182 Chapter8 Monitors and Blocking Synchronization 1 class LockedQueue { 2 final Lock lock new ReentrantLock); final Condition notFull lock.newCondition() final Condition notEmpty - lock.newCondition; 5 final Tl items: 6 int tail, head, count; 7 public LockedQueue(int capacity) f 8 items (T)new object[capacity]: 10 public void enq(T x) { 11 lock.lock): 12 try I 13 while (count items.1ength) notFul1.await); items [tail] x; 14 15 16 if (Htailitems.1ength) tail 0; 18 19 20 finally l ++count; notEmpty.signa1): lock.unlock); 23 24 public T de) I 25 1ock.lockO; 26 try f 27 28 29 30 while (count 0) notEmpty.await) Tx items [head]; if (++head items.length) head 0: .-count; 32 33 notFull.signal): 34 35 finally ( 36 lock.unlock()O: return x; 38 39 Figure 8.5 The LockedQueue class: a FIFO queue using locks and condisions Thet condition fields, one to detect when the queue becomes nonempcyx it becomes nonfull. Either of these two practices would fix the bounded bighe described. Each has a small performance penalty the cost of a lost wakeup. lava provides built-in support for monitors in dre ty blocks and methods, as well as built-in wait(), not methods. (See Appendix A.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!