[Contents] [Top] [Previous]


3. Language Elements

3.1 Creating Active Objects

An active object can be created using the UC++ keyword 'activenew'. The syntax is similar to the C++ keyword 'new'. One restriction on activenew, however, is that it can only be applied to a unitary entity of some class type, not to arrays of things; there is no activenew[] form. Thus, active objects are created using an expression of the form:

activenew class-id[(constructor-parameters)] [on resource-id]
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:

1. the initialisation value in a pointer declaration; and

2. the right-hand of an assignment to a pointer.

3.2 Destroying Active Objects

An active object is removed using the delete operator as in C++.

	// Pointer may point at an active

// or a passive object or primitive data
delete Pointer;
Unless the pointer points at an active object, delete behaves exactly as in C++.

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.

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.

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:

	// 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]

Generated with CERN WebMaker