Notes
Slide Show
Outline
1
Concepts and Terminology
2
Concepts and Terminology
  • Contents
    • Passive Objects
    • Active Objects
    • Threading
    • Concurrency
    • Concurrent Operations
    • Sequential Operations
    • Guarded Operations
    • Synchronisation
    • Critical Sections
    • Locking
    • Monitors
3
Terminology: Passive Object
  • A passive object never initiates a call
    • It rests passively
    • Responding to calls made on it
4
Terminology: Active Object
  • An active object initiates calls
    • It actively calls functions
5
What is a Thread?
  • A thread is an independent path of execution
    • Each thread has its own stack
    • Threads in a process share the same heap segment
    • Threads in a process share the same data segment
6
Single-Threading
  • One thread, one execution path
    • Thread starts at start of main, ends at end of main
7
Multi-Threading
  • Two or more threads!
8
Concurrency
  • Consider...
    • 2+ threads on the same path at the same time
9
Terminology: Concurrent Operations
  • Operations that are safe when concurrent
    • Accessing immutable state via const methods
    • Atomic queries
10
Non-Atomic What's the Time?
11
Atomic What's the Time?
12
Synchronisation
  • Most operations are not safe when concurrent
    • Unless you design them to be concurrent,
      assume operations are not concurrent
    • Concurrency is a huge design context,
      not just an implementation detail


13
Terminology: Critical Section
  • A section of code that is unsafe when concurrent
    • Access to critical section must be synchronised
    • Failure to synchronise causes undefined behaviour
    • Race conditions, deadlocks
    • Hair-pulling, teeth-gnashing
14
Question
  • How are critical sections enforced?
15
Locking
  • Lock access to critical section
16
Software Locks
  • Large variety of software locks
    • semaphore
      • binary, counting, blocked-set, blocked-queue, ...
    • mutex
      • read-write mutex, recursive mutex
    • “lock-free” synchronisation primitives
      • InterlockedIncrement( ), InterlockedDecrement( )

17
Mutex
  • Common synchronisation primitive
    • intra-process, inter-process
18
Question
  • Who is responsible for enforcement?
19
Terminology: Sequential Operation
  • Concurrent callers synchronise operation access
  • External complexity
20
External Locking
21
Terminology: Guarded Operation
  • Operation synchronises access to itself
  • Internal complexity
22
Internal Locking
23
Terminology: Monitors
  • Shared objects whose operations are guarded
    • Simplifies programming from class users POV
    • Don't call other public member functions from within the class if the synchronisation object is not re-entrant