E81 CSE 532S: Advanced Multi-Paradigm Software Development - PowerPoint PPT Presentation

About This Presentation
Title:

E81 CSE 532S: Advanced Multi-Paradigm Software Development

Description:

E81 CSE 532S: Advanced Multi-Paradigm Software Development The Active Object Pattern Chris Gill Department of Computer Science and ... – PowerPoint PPT presentation

Number of Views:84
Avg rating:3.0/5.0
Slides: 6
Provided by: cseWustl
Category:

less

Transcript and Presenter's Notes

Title: E81 CSE 532S: Advanced Multi-Paradigm Software Development


1
E81 CSE 532S Advanced Multi-Paradigm Software
Development
The Active Object Pattern

Chris Gill Department of Computer Science and
Engineering Washington University, St.
Louis cdgill_at_cse.wustl.edu
2
Active Object Pattern
  • Problem
  • Concurrent access risks races or deadlock,
    blocking, etc.
  • Solution activate the object
  • I.e., launch thread inside it
  • Decouples object method execution from invocation
  • Helps prevent deadlock
  • Helps increase concurrency
  • Implementation concerns
  • Ensuring thread safety
  • Increasing concurrency
  • Code and concurrency interact

Active Object
queue
requesting thread
worker thread
3
Details Retrieving Results
  • Completion of work is asynchronous
  • Blocking the request thread becomes a variant of
    the Monitor Object pattern
  • Can combine Active Object and ACT patterns
  • Encapsulate general completion rendezvous points
    as Futures
  • Can poll for result, or just block until its
    ready
  • Or, can post on requesting threads queue if its
    an active object as well

Active Object
Active Object
request queue
requesting thread
worker thread
result queue
4
Details Managing Queue Access
  • Need to synchronize access to queue methods
  • Particularly mutator methods
  • Want classic supplier-consumer behavior
  • Supplier sleeps when queue is full
  • Consumer sleeps when queue is empty
  • Need to manage carefully
  • Use condition variables
  • Increase concurrency opportunity
  • Maintain thread safety
  • Use high/low water marks
  • Avoid silly window syndrome

Active Object
queue
requesting thread
worker thread
5
Design and Implementation Concerns
  • Key trade-off for lock-based data structures
  • Ensuring thread safety (no meaningful race
    conditions)
  • Increasing concurrency opportunities (deadlock
    none)
  • Scope of serialization matters
  • How long is a lock held, and over how much data?
  • Minimize protected regions, use different locks
    if possible
  • I.e., right mutex is locked held for minimum
    time
  • Data structure and concurrency semantics interact
  • Queue interface motivates use of condition
    variables
  • Note that notify_all() may be needed for
    exception safety!
  • Move expensive copying/allocation outside locked
    regions
  • Associating a lock per item also reduces lock
    granularity
  • Decoupling items is then essential (hash vs. tree
    vs. array example)
  • Using a readers/writer lock also may be helpful
    in some cases
Write a Comment
User Comments (0)
About PowerShow.com