Notes
Slide Show
Outline
1
Functions
2
Functions
  • Contents
    • Global Functions
    • Member Functions
    • Remember Functions
    • Callable Interface
    • Adaptors
    • Currying
    • Cloning
    • Any Function
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
      • Direct Member Function
      • Indirect Member Function
    • How can we “thread” them?
4
Global C Function
  • A global C function has no implicit object
    • How can we “thread” a global C function?
5
Global C++ Function
  • A global C++ function has no implicit object
    • How can we “thread” a global C++ function?
6
Member function
  • A member function has a this object
    • How can we “thread” a member function?
7
Remember function
  • A member function can be called indirectly
    • How can we “thread” a remember function?
8
Callable Interface
  • To make progress we need an interface
    • All functions are callable
9
Callable Global Function
  • An example of the Adapter pattern
10
Callable Global C Function
  • Example of adapting a global C function
11
Currying
  • Arguments and return values can be curried
12
Callable Global C++ Function
  • Example of adapting a global C++ function
13
Callable Member Function
  • Another example of the Adapter pattern
14
Callable Member Function
  • In use
15
Function Lifetime
  • A threaded function has lifetime constraints
    • “function” must persist beyond scope of invoker
16
Cloning
  • Make the callable functions...
    • Polymorphically copyable
    • Polymorphically destructable
17
Callable Global Function Again
  • This time with cloneability
18
Callable Member Function Again
  • This time with cloneability
19
Any Function
  • Now we can create a function abstraction
    • Easy to use, ready to be threaded
20
Null Object Pattern
  • Simplifies implementation...
21
Default Constructor
  • Functions can be “null”
22
Argument Constructor
  • Clones the callable parameter
23
Copy Constructor
  • Clones the function parameter
24
Destructor
  • Deletes the callable body
25
Copy Assignment Operator
  • Copy Before Release idiom
26
Function Call Operator
  • Common C++ idiom