6.1 Overview

Ru-Brd

The ACE Task framework provides powerful and extensible object-oriented concurrency capabilities that can spawn threads in the context of an object, as well as transfer and queue messages between objects executing in separate threads. This framework can be applied to implement key concurrency patterns [POSA2], such as:

  • The Active Object pattern, which decouples the thread that invokes a method from the thread that executes the method. This pattern enhances concurrency and simplifies synchronized access to objects executing in the context of one or more threads.

  • The Half-Sync/Half-Async pattern, which decouples asynchronous and synchronous processing in concurrent systems to simplify programming without unduly reducing performance. This pattern introduces three layers: one for asynchronous (or reactive) processing, one for synchronous service processing, and a queueing layer that mediates communication between the asynchronous/reactive and synchronous layers .

This chapter shows how these patterns, and the ACE Task framework that reifies them, can be applied to develop concurrent object-oriented applications at a higher level of abstraction than existing C operating system APIs and C++ wrapper facades. The ACE Task framework consists of the following classes that networked applications can use to spawn and manage threads and pass messages between one or more threads within a process:

ACE Class

Description

ACE_Message_Block

Implements the Composite pattern [GoF] to enable efficient manipulation of fixed- and variable- sized messages

ACE_Message_Queue

Provides an intraprocess message queue that enables applications to pass and buffer messages between threads in a process

ACE_Thread_Manager

Allows applications to portably create and manage the lifetime, synchronization, and properties of one or more threads

ACE_Task

Allows applications to create passive or active objects that decouple different units of processing; use messages to communicate requests , responses, data, and control information; and can queue and process messages sequentially or concurrently

The most important relationships between the classes in the ACE Task framework are shown in Figure 6.1. This framework provides the following benefits:

Figure 6.1. The ACE Task Framework Classes

  • Improves the consistency of programming style by enabling developers to use C++ and object-oriented techniques throughout their concurrent networked applications. For example, the ACE_Task class provides an object-oriented programming abstraction that associates OS-level threads with C++ objects.

  • Manages a group of threads as a cohesive collection. Multithreaded networked applications often require multiple threads to start and end as a group. The ACE_Task class therefore provides a thread group capability that allows other threads to wait for an entire group of threads to exit before continuing their processing.

  • Decouples producer and consumer threads that run concurrently and collaborate by passing messages via a synchronized message queue.

  • Integrates concurrent processing, such as the Half-Sync/Half-Async pattern's synchronous layer, with the ACE Reactor framework discussed in Chapter 3 or the ACE Proactor framework discussed in Chapter 8.

  • Facilitates dynamic configuration of tasks via integration with the ACE Service Configurator framework discussed in Chapter 5. Developers therefore need not commit prematurely to concurrency decisions at design time or even at run time. Tasks can instead be designed to run according to configurations that may change as deployment site resources and dynamic conditions dictate .

The ACE_Message_Block and ACE_Thread_Manager classes were described in Chapters 4 and 9 of C++NPv1, respectively. This chapter therefore focuses largely on describing the capabilities provided by the ACE_Message_Queue and ACE_Task classes. However, we illustrate how all the classes in the ACE Task framework can be used to enhance the concurrency of our client and server logging daemons. If you aren't familiar with the Active Object and Half-Sync/Half-Async patterns from POSA2 we recommend that you read about them first before delving into the detailed examples in this chapter.

Ru-Brd


C++ Network Programming
C++ Network Programming, Volume I: Mastering Complexity with ACE and Patterns
ISBN: 0201604647
EAN: 2147483647
Year: 2002
Pages: 65

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net