|
1
|
|
|
2
|
- Contents
- Passive Objects
- Active Objects
- Threading
- Concurrency
- Concurrent Operations
- Sequential Operations
- Guarded Operations
- Synchronisation
- Critical Sections
- Locking
- Monitors
|
|
3
|
- A passive object never initiates a call
- It rests passively
- Responding to calls made on it
|
|
4
|
- An active object initiates calls
- It actively calls functions
|
|
5
|
- 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
|
- One thread, one execution path
- Thread starts at start of main, ends at end of main
|
|
7
|
|
|
8
|
- Consider...
- 2+ threads on the same path at the same time
|
|
9
|
- Operations that are safe when concurrent
- Accessing immutable state via const methods
- Atomic queries
|
|
10
|
|
|
11
|
|
|
12
|
- 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
|
- 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
|
- How are critical sections enforced?
|
|
15
|
- Lock access to critical section
|
|
16
|
- 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
|
- Common synchronisation primitive
- intra-process, inter-process
|
|
18
|
- Who is responsible for enforcement?
|
|
19
|
- Concurrent callers synchronise operation access
- External complexity
|
|
20
|
|
|
21
|
- Operation synchronises access to itself
- Internal complexity
|
|
22
|
|
|
23
|
- 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
|