Chapter 9.1-9.3 Linked Lists: The Role of Locking Magnus Andersson - - PowerPoint PPT Presentation

chapter 9 1 9 3 linked lists the role of locking
SMART_READER_LITE
LIVE PREVIEW

Chapter 9.1-9.3 Linked Lists: The Role of Locking Magnus Andersson - - PowerPoint PPT Presentation

Chapter 9.1-9.3 Linked Lists: The Role of Locking Magnus Andersson Introduction Fine-grained Synchronization Optimistic Synchronization Lazy Synchronization Non-blocking Synchronization Set on top of a Linked list public


slide-1
SLIDE 1

Chapter 9.1-9.3 Linked Lists: The Role of Locking

Magnus Andersson

slide-2
SLIDE 2

Introduction

  • Fine-grained Synchronization
  • Optimistic Synchronization
  • Lazy Synchronization
  • Non-blocking Synchronization
slide-3
SLIDE 3

Set on top of a Linked list

public interface Set<T> { boolean add(T x); boolean remove(T x); boolean contains(T x); }

slide-4
SLIDE 4

Linked list node

private class Node { volatile T item; volatile int key; volatile Node next; }

item key next item key next item key next Head Tail Sored on key

slide-5
SLIDE 5

Linked list node

item key next item key next item key next Head Tail item key next item key next item key next Head Tail item key next Removing Adding

slide-6
SLIDE 6

Concurrent Reasoning

Item A Item B Item C Item A key next Item B key next Item C key next Head Tail Abstract value Concrete representation

slide-7
SLIDE 7

Concurrent Reasoning

  • Invariants

– Properties that hold from creation and onward – Always preserved by methods

  • In this case add, remove and contains

could potentially break invariants

– Why only these?

  • Private

– Freedom from interference

slide-8
SLIDE 8

Concurrent Reasoning

contains(T x) remove(T x) add(T x)

slide-9
SLIDE 9

Concurrent Reasoning

contains(T x) remove(T x) add(T x) Contract

slide-10
SLIDE 10

Concurrent Reasoning

  • Representation invariant

– Contract – Pre- and Post-conditions that everyone agrees on

  • Concrete representation must make sense for the given

abstract values

  • In this case:

– Sentinels may not be added or removed – Sorted by unique keys

slide-11
SLIDE 11

Concurrent Reasoning

  • Given a concrete representation, which set

does it represent?

– Abstraction map

  • In this case:

– All values reachable from the head

Item A Item B Item C Item A key next Item B key next Item C key next Head Tail Abstraction map

slide-12
SLIDE 12
  • Consistency model

– Linearizability

  • Single “operation” (atomic, critical section)

– Stricter than sequential consistency

  • Some examples can be found at

– http://kisalay.com/2011/04/26/linearizability-3/

Thread, Method call

Concurrent Reasoning

Invocation Response Linearization point

slide-13
SLIDE 13
  • Serializable

– Parallel execution must appear to be executed serially – May reorganize tasks between threads “out-of-

  • rder”
  • Linearizablity

– Stricter ordering between method calls on an object

  • Response -> Invocation order must be maintained
  • Chapter 3 in the book…

Concurrent Reasoning

slide-14
SLIDE 14

Concurrent Reasoning

  • Non-blocking properties

– lock-free (“Some calls finishes after a number of steps”)

  • Non-blocking
  • Allows for concurrent access without corruption

– Though not without restrictions (read the friendly manual)

  • Even if one thread is suspended, others must be able to

access uncorrupted data

  • Must retry on failure (unbounded)

– wait-free (“All calls finishes after a number of steps”)

  • Bounded number of steps
  • Always make progress
slide-15
SLIDE 15

Concurrent Reasoning

Blocking Non-Blocking All make progress Some make progress Lock-free Wait-free Deadlock-free Starvation-free

slide-16
SLIDE 16

Exercises

Blocking Non-Blocking All make progress Some make progress Lock-free Wait-free Deadlock-free Starvation-free

1. Give two examples of scenarios (not the ones from the chapter) where you think it would be practical and/or performant to use…

– a) a wait-free method – b) a lock-free method

  • 2. Where it makes sense to do so:

From the assignments given by the other students this lecture – categorize each method implemented to one of the four blocking categories. Motivate your conclusions.

slide-17
SLIDE 17

Fin

slide-18
SLIDE 18

Concurrent Reasoning [BACKUP]

  • Liveness and safety considerations

– Safety property: “Linearizability”

  • “Linearizability provides the illusion that each operation applied by concurrent

processes takes effect instantaneously at some point between its invocation and its response, implying that the meaning of a concurrent object’s operations can be given by pre- and post-conditions.”

– M. P. Herlihy and J. M. Wing. Linearizability: a correctness condition for concurrent objects. TOPLAS, 12:463–492, 1990.

slide-19
SLIDE 19

Concurrent Reasoning [BACKUP]

  • Linearizability

– Wikipedia has a fairly comprehensible explanation – http://en.wikipedia.org/wiki/Linearizability

  • Non-blocking properties

– A good description can be found here: – http://www.justsoftwaresolutions.co.uk/threadin g/non_blocking_lock_free_and_wait_free.html