03~Chapter_03 - C o nc urre ntO b je c ts Please read...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
C o nc urre nt O b je c ts Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Please read sections 3.7 and 3.8
Background image of page 1

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

View Full DocumentRight Arrow Icon
Art of Multiprocessor Programming 2 Concurrent Computaton memory object object
Background image of page 2
Art of Multiprocessor Programming 3 Objectivism What is a concurrent object? How do we  describe  one? How do we  implement  one? How do we  tell if we re right ?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Art of Multiprocessor Programming 4 Objectivism What is a concurrent object? How do we  describe  one? How do we  tell if we re right ?
Background image of page 4
Art of Multiprocessor Programming 5 FIFO Queue: Enqueue Method q.enq ( )
Background image of page 5

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

View Full DocumentRight Arrow Icon
Art of Multiprocessor Programming 6 FIFO Queue: Dequeue Method q.deq()/
Background 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[])  Object[capacity];   }
Background image of page 7

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

View Full DocumentRight 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
Background 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[])    Object[capacity];   } 0 1 capacity-1 2 head tail y z Initially head = tail
Background image of page 9

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

View Full DocumentRight Arrow Icon
Art of Multiprocessor Programming 10 Implementation:  Deq public   T deq()  throws      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
Background image of page 10
Art of Multiprocessor Programming 11 Implementation:  Deq    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
Background image of page 11

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

View Full DocumentRight Arrow Icon
Art of Multiprocessor Programming 12 Implementation:  Deq    lock.lock();              try {            if  
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/09/2011 for the course ENGINEERIN 247 taught by Professor Staff during the Fall '09 term at Rutgers.

Page1 / 192

03~Chapter_03 - C o nc urre ntO b je c ts Please read...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online