{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

03~Chapter_03 - ConcurrentObjects...

Info icon This preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Concurrent Objects Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Please read sections 3.7 and 3.8
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 2 Concurrent Computaton memory object object
Image of page 2
Art of Multiprocessor Programming 3 Objectivism What is a concurrent object? How do we  describe  o ne ? How do we  implement  o ne ? How do we  tell if we ’re right ?
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 4 Objectivism What is a concurrent object? How do we  describe  o ne ? How do we  tell if we ’re right ?
Image of page 4
Art of Multiprocessor Programming 5 FIFO Queue: Enqueue Method q.enq ( )
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 6 FIFO Queue: Dequeue Method q.deq()/
Image of page 6
Art of Multiprocessor Programming 7       A Lock-Based Queue class  LockBasedQueue<T> {     int  head, tail;      T[] items;     Lock lock;     public  LockBasedQueue( int  capacity) {         head = 0; tail = 0;         lock =  new  ReentrantLock();          items = (T[])  new  Object[capacity];   }
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 8       A Lock-Based Queue class LockBasedQueue<T> {     int  head, tail;      T[] items;     Lock lock;      public LockBasedQueue(int capacity) {         head = 0; tail = 0;         lock = new ReentrantLock();         items = (T[]) new Object[capacity];   } 0 1 capacity-1 2 head tail y z Queue fields protected by  single shared lock
Image of page 8
Art of Multiprocessor Programming 9       A Lock-Based Queue class LockBasedQueue<T> {      int head, tail;     T[] items;     Lock lock;     public  LockBasedQueue(int capacity) {         head = 0; tail = 0;         lock =  new  ReentrantLock();         items = (T[])  new  Object[capacity];   } 0 1 capacity-1 2 head tail y z Initially head = tail
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 10  Implementation: Deq public   T deq()  throws   EmptyException {    lock.lock();                try {           if  (tail == head)                throw new  EmptyException();           T x = items[head % items.length];           head++;           return  x;        }  finally  {             lock.unlock();       }   0 1 capacity-1 2 head tail y z
Image of page 10
Art of Multiprocessor Programming 11  Implementation: Deq public T deq() throws EmptyException {    lock.lock();                 try {           if (tail == head)                throw new EmptyException();           T x = items[head % items.length];           head++;           return x;       } finally {           lock.unlock();       }   Method calls   mutually exclusive 0 1 capacity-1 2 head tail y z
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}