Top Up Prev Next Bottom Contents Index Search

10.5 Programming Stars in the PN Domain

Unlike portholes in the SDF domain, the number of tokens consumed by an input or produced by an output can be dynamic in the PN domain. This is indicated with the P_DYNAMIC porthhole attribute.


input {
name { a }
type { int }
attributes { P_DYNAMIC }
}
For dynamic ports, it is necessary to invoke the receiveData and sendData methods explicitly. Note that the receiveData method must be used to initialize outputs. For static ports, the receiveData and sendData methods are invoked implicitly and should not be used in the go method.

Because a separate thread of execution is created for each star, the go method of a PN star is not required to terminate. As a programmer, you are free to use infinite loops, such as while(TRUE) { ... } within the go method of your PN stars. This may be necessary if you access a porthole (requiring a blocking read) before entering the main loop of the process. In the future, such code could be placed in the star's begin method, but currently (as of release 0.6) the begin method is executed before the star's thread is created.

go {
// Read both inputs the first time.
a.receiveData();
b.receiveData();
while (TRUE) {
output.receiveData(); // Initialize the output.
if (int(a%0) < int(b%0)) {
output%0 = a%0;
output.sendData();
a.receiveData();
}
else if (int(a%0) > int(b%0)) {
output%0 = b%0;
output.sendData();
b.receiveData();
}
else { // Remove duplicates.
output%0 = a%0;
output.sendData();
a.receiveData();
b.receiveData();
}
}
}
Instead of using an infinite loop, most PN stars rely on the run method of DataFlowProcess to repeatedly invoke the star's go method.



Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.