When executed, this expression creates a virtual processor and constructs an active object in that processor. The address of the active object is returned. This expression may be used in any context where an object address is expected. Typical uses are:activenew class-id[(constructor-parameters)] [on resource-id]
1. the initialisation value in a pointer declaration; and
2. the right-hand of an assignment to a pointer.
Where the pointer points at an active object, the effect is similar: the destructor, if defined, is called synchronously and the virtual processor containing the object is terminated. Any resources associated with the object are released, these include any local data or passive objects. Any files opened will be closed. In the case of a passive object, unless a destructor took appropriate action, store would not be released and files would remain open.
The normal C++ syntax is used where a synchronous call is required. Implicit member function calls i.e. of constructors, destructors and operators are made synchronously.
An asynchronous call is specified by the asynchronous function call operator (@@). The effect of making an asynchronous call of a member function which returns a result is not defined. (@@) may be used to indicate asynchronous calls of constructors and destructors.
Examples:
Generated with CERN WebMaker
3.2 Destroying Active Objects
An active object is removed using the delete operator as in C++.
Unless the pointer points at an active object, delete behaves exactly as in C++. // Pointer may point at an active
// or a passive object or primitive data
delete Pointer;
3.3 The On Clause
The 'on resource-id' clause provides a means to determine resources used by each new object. 'resource-id' may be either a integer value or a null terminated string. The effect of this clause is implementation dependant. If this clause is omitted, the effect is the same as if 'on 0' had been supplied.3.4 Active Object Member Function Calls
An active object member function may be called either synchronously or asynchronously. In a synchronous call, the caller is suspended until the function returns (with or without a result). In an asynchronous call, the caller continues execution at the same time as the called function. This is the mechanism whereby parallelism is achieved.
// Synchronous call of X::X( a, b, c )
X* p = activenew X( a, b, c );
// Synchronous call of X::f( i, j, k )
r = p->f( i, j, k );
// Asynchronous call X::g( p, q, r )
p->g(@ p, q, r @);
// Synchronous call of X::~X()
delete p;
UC++ - 02 MAY 95
[Contents] [Top] [Previous]