Concurrency Design Patterns - PowerPoint PPT Presentation

1 / 60
About This Presentation
Title:

Concurrency Design Patterns

Description:

Abstract thread: super class, associates with scheduler. ... Not stable. Complex. Related Patterns. Not as common as SPP. More complex than other patterns ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 61
Provided by: fer8152
Category:

less

Transcript and Presenter's Notes

Title: Concurrency Design Patterns


1
Concurrency Design Patterns
  • By
  • Kalpana Nallavolu
  • Nestor Rivera
  • Feras Batarseh

2
Design Patterns
  • A design pattern is a formal way of documenting
    successful solutions to problems.
  • Reusability, modularity, win time.
  • Resign Pattern
  • Ex fatal, misbehavior.

3
Contributors
  • Christopher Alexander
  • GoF

4
Concurrency Design Patterns
  • Concurrency Pattern
  • Message Queuing Pattern
  • Interrupt Pattern
  • Guarded Call Pattern
  • Rendezvous Pattern
  • Cyclic Executive Pattern
  • Round Robin Pattern
  • Static Priority Pattern
  • Dynamic Priority Pattern

5
Background
  • Thread
  • Concurrency
  • Concurrency Architecture
  • Active Object
  • Passive objects

6
Collaboration Of Objects
7
Collaboration Of Objects 2
  • The active object accept messages and delegate
    them to the internally contained application
    objects for processing.
  • The issues around the concurrency management are
    varied depending
  • 1) The threads are completely independent
  • 2) The threads are not really independent.

8
Message Queuing Pattern
9
Message Queuing Pattern
  • It provides a simples means of communication
    among threads.
  • It uses asynchronous communication.
  • Information shared among threads is passed by
    value to the separate thread.
  • Advantages and disadvantages

10
Pattern Structure
11
Sample Model
12
Interrupt Pattern
13
Interrupt Pattern
  • In many real-time applications, certain events
    must be responded quickly and efficiently
    regardless of what system is doing.
  • This method is rarely used as only concurrency
    strategy
  • Advantages and disadvantages.

14
Pattern Structure
15
Sample Model
16
Guarded Call Pattern
17
Guarded Call Pattern Abstract
  • Problem with Message Queuing Pattern?
    Asynchronous slow
  • What if urgency? Alternative -gt synchronously
    invoke a method of an object
  • Data integrity is key -gt mutual exclusion
  • Need to avoid -gtsynchronization deadlock
    problems

18
Guarded Call Pattern Collaboration Roles I
  • Server Thread ltltactive objectgtgt
  • Server Object
  • Shared Resource
  • Protection with Mutex
  • Client Thread ltltactive objectgtgt
  • Client object
  • Synchronously invoke method

19
Guarded Call Pattern Collaboration Roles II
  • Boundary Object
  • Protected interface to server objects with
    operations
  • Mutex
  • Mutual exclusion semaphore object
  • Permits only single caller through time
  • Safer if invoked by relevant operations
  • Locks and unlocks shared resource
  • Blocks client threads

20
Guarded Call Pattern Collaboration Roles III
  • Server
  • Uses the shared resource object
  • Provides the service to client across the thread
    boundary
  • Shared Resource
  • Provides data or service
  • Shared by multiple servers
  • Integrity must be protected gt serialization of
    access

21
Guarded Call Pattern - Consequences
  • Timely response (unless services are locked)
  • Simplification no interaction among servers gt
    boundary object, contain shared resource one
    mutex/server

22
Guarded Call Pattern Related Patterns
  • Message Queuing, Interrupt, Guarded Call
    Rendezvous could be mixed
  • Race conditions may appear
  • If server is stateful, monitor on server may be
    needed

23
Guarded Call Pattern Class Diagram
24
Guarded Call Pattern Example - Structure
25
Guarded Call Pattern Example - Scenario
26
Rendezvous Pattern
27
Rendezvous Pattern
  • Simplified form of Guarded Call Pattern
    (synchronize threads)
  • Rendezvous Object gt means for synchronization
    (synchronization point, policy or precondition)

28
Rendezvous Pattern - Abstract
  • Precondition gt specified to be true prior to an
    action/activity
  • Behavioral model gt each thread registers with
    Rendezvous class and blocks until released

29
Rendezvous Pattern Collaboration Roles I
  • Callback holds address of client thread
  • Client Thread
  • At synchronization points, register
  • Pass their callbacks
  • i.e. notify() called once condition met

30
Rendezvous Pattern Collaboration Roles II
  • Rendezvous
  • Manages thread synchronization
  • Has register() operation
  • Sync Policy
  • Reifies set of preconditions into single concept
    i.e. Registration count (Thread Barrier Pattern)

31
Rendezvous Pattern Class Diagram
32
Rendezvous Pattern Sync Policy State Chart
33
Rendezvous Pattern Example - Structure
34
Rendezvous Pattern Example - Scenario
35
Cyclic Executive Pattern
36
Cyclic Executive Pattern
  • Very small systems (execution predictability is
    crucial)
  • Easy to implement
  • Can run in memory constraint systems (no RTOS)
  • Executes tasks in turn, from first to last and
    starts over again (cycle)

37
Cyclic Executive Pattern Collaboration Roles
  • Abstract Thread
  • Super class for concrete thread
  • Interface to the scheduler
  • Concrete Thread
  • ltltactive objectgtgt
  • Contains passive objects
  • Scheduler
  • Initializes system (loads tasks)
  • Runs each of them in turn in perpetuity

38
Cyclic Executive Pattern Properties of
Applications
  • Constant number of tasks
  • Amount of task time is unimportant or consistent
  • Tasks are independent
  • Usage of shared resources complete after each
    task
  • Sequential ordering of tasks is adequate

39
Cyclic Executive Pattern Pros and Cons
  • Primary advantage gt simplicity
  • Primary Disadvantages
  • Lack of flexibility
  • Non-optimality
  • Instability to violation of its assumptions
  • Response to incoming event deadline gt cycle
    time
  • No criticality or urgency all threads are
    equally important.

40
Cyclic Executive Pattern Class Diagram
41
Cyclic Executive Pattern Example - Structure
42
Cyclic Executive Pattern Example - Scenario
43
Round Robin Pattern
44
Introduction
  • Hardcore real time deadline!
  • A fairness scheduling method.
  • All tasks progress than specific deadline to be
    met.
  • Entire set movement.

45
The Model
  • Abstract thread super class, associates with
    scheduler.
  • Concrete thread (active thread) real work of the
    system.
  • Scheduler initialize the tasks and run them.
  • Stack control and data variables, return
    variables
  • Task control block
  • Timer ticks for scheduler, front end to the
    hardware timer, switch task()

46
Pros and Cons
  • All tasks get the chance to run.
  • Misbehaving task wont ruin the system.
  • Scale up better to big systems.
  • Higher switching time
  • All tasks take the same time slice!
  • Priority?

47
Related Patterns
  • More complex than cyclic executive
  • Less complex than priority patterns, discussed
    next.
  • Special kind that gives each task its time.

48
Static Priority Pattern
49
Introduction
  • Priorities predefined.
  • Common approach, simple, large number of tasks.
  • Urgency (time) Criticality (importance)

50
The Model
  • Abstract thread
  • Blocked queue queue for TCB, blocked tasks in,
    out to ready queue.
  • Concrete thread
  • Shared resources
  • Mutex semaphore object that allows one caller
    object (thread) to access shared resources.
  • Mutex ID, entry point.

51
The Model 2
  • Ready queue reference to tasks ready to execute
    next.
  • even running tasks could be interrupted by
    looking at the RQ.
  • Scheduler calls start address of higher and
    ready thread.
  • Stack parameters for threads.
  • Task control block priority and entry address

52
Pros and Cons
  • Simplicity
  • Stability
  • Changing conditions, reallocation? (DPP)
  • Low priority tasks?

53
Dynamic Priority Pattern
54
Introduction
  • Automatically update of tasks priorities.
  • Urgency over criticality, thus Earliest deadline
    first.
  • Sets priority as time remaining function.

55
The Model
  • Abstract thread
  • Blocked queue queue for TCB, blocked tasks in,
    out to ready queue.
  • Concrete thread
  • Ready queue reference to tasks ready to execute
    next, closest to deadline on top.
  • even running tasks could be interrupted by
    looking at the RQ.

56
The Model 2
  • Scheduler computes the priority dynamically due
    to closest deadline.
  • Stack return addresses and parameters for
    threads.
  • Task control block priority and entry address
    after scheduler computations.
  • Shared resources
  • Mutex semaphore object that allows one caller
    object (thread) to access shared resources.

57
Pros and Cons
  • Flexible
  • Optimal
  • Scales well to large systems
  • Not stable
  • Complex

58
Related Patterns
  • Not as common as SPP
  • More complex than other patterns

59
References
  • book Real time design patterns Patterns
    robust scalable architecture for real-time
    systems
  • book Design patterns Elements of reusable
    object-oriented software
  • Gomma, Hassan Software Design Methods for
    concurrent and real timeSystems, Reading ,
    Addison-Wesley 1993
  • IEEE Papers Database
  • wikipedia.com...and a couple of other websites

60
  • Thank you for your attention.
  • Questions?
Write a Comment
User Comments (0)
About PowerShow.com