Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Active Object Pattern

Similar presentations


Presentation on theme: "The Active Object Pattern"— Presentation transcript:

1 The Active Object Pattern
E81 CSE 532S: Advanced Multi-Paradigm Software Development The Active Object Pattern Chris Gill Department of Computer Science and Engineering Washington University, St. Louis Title slide

2 Active Object Pattern Problem Solution: “activate” the object
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 it’s ready Or, can post on requesting thread’s queue if it’s 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


Download ppt "The Active Object Pattern"

Similar presentations


Ads by Google