09~Chapter_10_and_11

09~Chapter_10_and_11 - C oncurre Que s and S nt ue tacks C...

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

View Full Document Right Arrow Icon
Concurrent Queues and Stacks Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Background image of page 1

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 2 The Five-Fold Path Coarse-grained locking Fine-grained locking Optimistic synchronization Lazy synchronization Lock-free synchronization
Background image of page 2
Art of Multiprocessor Programming© Herlihy-Shavit 2007 3 Another Fundamental Problem We told you about Sets implemented using linked lists Next: queues stacks
Background image of page 3

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 4 Queues & Stacks Both: pool of items Queue enq() & deq() First-in-first-out (FIFO) order Stack push() pop() Last-in-first-out (LIFO)
Background image of page 4
Art of Multiprocessor Programming© Herlihy-Shavit 2007 5 Bounded vs Unbounded Bounded Fixed capacity Good when resources an issue Unbounded Holds any number of objects
Background image of page 5

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 6 Blocking vs Non-Blocking Problem cases: Removing from empty pool Adding to full (bounded) pool Blocking Caller waits until state changes Non-Blocking Method throws exception
Background image of page 6
Art of Multiprocessor Programming© Herlihy-Shavit 2007 7 This Lecture Bounded, Blocking, Lock-based Queue Unbounded, Non-Blocking, Lock-free ABA problem Unbounded Non-Blocking Lock-free Stack Elimination-Backoff
Background image of page 7

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 8 Queue: Concurrency enq(x ) y=deq( ) enq() and deq() work at different ends of the object tail head
Background image of page 8
Art of Multiprocessor Programming© Herlihy-Shavit 2007 9 Concurrency enq(x ) Challenge: what if the queue is empty or full? y=deq( ) tail head
Background image of page 9

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 10 Bounded Queue Sentinel head tail
Background image of page 10
Art of Multiprocessor Programming© Herlihy-Shavit 2007 11 Bounded Queue head tail First actual item
Background image of page 11

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 12 Bounded Queue head tail Lock out other deq() calls deqLock
Background image of page 12
Art of Multiprocessor Programming© Herlihy-Shavit 2007 13 Bounded Queue head tail Lock out other enq() calls deqLock enqLock
Background image of page 13

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 14 Not Done Yet head tail deqLock enqLock Need to tell whether queue is full or empty
Background image of page 14
Art of Multiprocessor Programming© Herlihy-Shavit 2007 15 Not Done Yet head tail deqLock enqLock Permission to enqueue 8 items permits 8
Background image of page 15

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 16 Not Done Yet head tail deqLock enqLock Incremented by deq() Decremented by enq() permits 8
Background image of page 16
Art of Multiprocessor Programming© Herlihy-Shavit 2007 17 Enqueuer head tail deqLock enqLock permits 8 Lock enqLock
Background image of page 17

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 18 Enqueuer head tail deqLock enqLock permits 8 Read permits OK
Background image of page 18
Art of Multiprocessor Programming© Herlihy-Shavit 2007 19 Enqueuer head tail deqLock enqLock permits 8 No need to lock tail
Background image of page 19

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 20 Enqueuer head tail deqLock enqLock permits 8 Enqueue Node
Background image of page 20
Art of Multiprocessor Programming© Herlihy-Shavit 2007 21 Enqueuer head tail deqLock enqLock permits 8 7 getAndDecrement()
Background image of page 21

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming© Herlihy-Shavit 2007 22 Enqueuer head tail deqLock enqLock permits 8 Release lock 7
Background image of page 22
Image of page 23
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 198

09~Chapter_10_and_11 - C oncurre Que s and S nt ue tacks C...

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

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