|
1
|
|
|
2
|
- Contents
- Mutexes
- Synchronized Interface
- Sequential Operations
- External Locking
- Auto Locking
- Sychronizing Smart Pointer
- Guarded Operations
- Internal Locking
- Execute Around Pattern
|
|
3
|
- Common synchronization primitive
- intra-process, inter-process
|
|
4
|
- Synchronization primitives share intent
|
|
5
|
- Concurrent callers synchronize operation access
|
|
6
|
|
|
7
|
- Why
- try/catch/throw not
in embedded C++
- Bloat, more code
than before
- Duplication, must be
repeated every time
- Complexity, code is
harder to follow
- Responsibility, is
with callers
- Scalability, is poor
- Intrusive
|
|
8
|
- “Resource Release in Finalisation” idiom
|
|
9
|
- Why?
- No try/catch/throw
- No bloat
- No duplication
- Not complex
- Non intrusive
- Scalable, easy to lock statement sequences
- But...
- Responsibility is still with callers
- User must perform two actions
|
|
10
|
- Synchronizing smart pointer
|
|
11
|
- Can be refactored into template class
|
|
12
|
|
|
13
|
- Can be nested inside synch_ptr class
|
|
14
|
- Copy c'tor?, copy assignment?
|
|
15
|
- Single statement granularity
- Don't use twice in same statement
- Non re-entrant lock will cause deadlock
|
|
16
|
- Operation synchronizes access to itself
|
|
17
|
|
|
18
|
|
|
19
|
- Because...
- Encapsulated resource
- Simple model of use
- But...
- Locks at single
operation level
- Sometimes need
coarser granularity
- Eg, what you want to
enqueue a sequence of
tasks operations?
|
|
20
|
- Execute Around + Command pattern
|
|
21
|
- Execute Around + Query pattern
|
|
22
|
|
|
23
|
|