Notes
Slide Show
Outline
1
Threads
2
Threads
  • Contents
    • Threading API's
    • Delegation Based Threads
    • Inheritance Based Threads
    • Thread Adaptor
    • Needle and Thread


3
What is a Thread?
  • A thread is the path traced by a function as it runs
    • C++ supports several kinds of functions
      • Global Function
      • Member Function
      • Remember Function
    • How can we “thread” them?
4
Thread Bare
5
1: Delegation Based Thread
6
Thread Internals
7
Thread Destructor
  • Lifetime of thread must be contained in lifetime of thread object
    • Make thread object part of whole object
    • Whole object becomes active
8
2: Inheritance Based Thread
9
Thread Adaptor
10
Thread Internals
11
Thread Gotcha
  • Don't make threads auto-runnable
    • Leads to non-deterministic bugs in many designs
    • Initialisation and execution are separate concepts
    • What if you want to delay execution?


12
3: Threader
13
Joiner
14
Needle
  • Can be refactored using Cheshire Cat idiom
15
Needle Point