Operators take and drop can be used to take a role
and to drop a role respectively.
In the following, R stands for the name of some role and .
To perform initialization when a role is taken and to clean up
when a role is dropped, we define constructor and destructor rules
as follows.
Arguments of the constructor rules are optional.
For each role we can define one or more constructor rules which are fired
at a cocavm when a participant takes on this role.
Only the constructor whose arguments unify with those of the take
predicate is chosen to execute upon initialization.
However, we define at most one destructor for each role. The destructor is fired at a cocavm when the role is dropped. At this point, it becomes inappropriate for any rules defined for that role to continue their execution. Our strategy is to mark all the arrival message and event queues in the cocavm so that no more messages or events will be processed after the mark. When the cocavm comes to a quiescent state, the destructor is fired to clean up.