Synchronizing two D3 processes
.mdOn most conventional D3 implementations, synchronizing two D3 processes is done either through polling for the existence of a file or, more preferably, by using a FlashBASIC lock instruction. On most implementations, however, the FlashBASIC lock instruction itself involves, internally, a polling, thus causing the waiting process to consume CPU resources. By using signals, it is possible to have a process waiting for a signal to occur (a Break, log off or a signal generated by another process, possibly a UNIX process or a D3 process from another D3 virtual machine) without any CPU consumption.
This example illustrates one phantom task waiting for a signal sent by a user to read a message in a pipe where the user has deposited the message. In practice, this communication with the message would be better achieved via UNIX messages, but this is merely an example. Also, this is a one to one communication. Multiple partners in this scheme would require semaphores. The server process makes itself visible to the entire system (D3 and UNIX) by writing a temporary file that contains its process ID, which other processes use to send a signal to it.
Phantom task waiting for a signal in a one-to-one pipe communication example
The signal handler uses SIGUSR1. The message is in ASCII, containing a header and some data, and displays as:
Synchronizing two D3 processes
Steps to synchronize two D3 processes using signals from another virtual machine: