The method initialize sets pendings and pendingR for all neighbors and the
variable pulse to 0. We have assumed that t,he communication topology is given
by an undirected graph and that comm.neighbors has the list of all neighbors.
The method handleMsg is implemented as follows. When a message is received
at the application, it is determined whether any message has already been received
from the source in the current, pulse. If there is such a message, then this message
belongs to the next pulse and the process waits for rcvEnabled[src] to become
true. Otherwise, this message is meant for this pulse and source is removed from
the list pendingR. At this point, the tag of the message is checked to see if it is a null
message (of type synchNull) used only for the synchronizer. If it is not, the message
is passed on to the application. If a message hns been received in this pulse from
each of the neighbors, that is, pendingR is empt,y, then the application can continue
to the next pulse and the thread that may be blocked in nextpulse is signaled. To
send a message, we simply remove t,he destination from the list pendingS.
Whenever t.he application layer calls nextpulse, t,he synchronizer first. ensures
that, every neighbor is sent exactly one message in the last, pulse. After increnienting
t,he pulse number, it waits to receive exactly one message from every neighbor. This
is achieved bu waiting for t,he list pendingR to be empty. When this condit,ion
becomes true, it is ready for the next pulse.
Note t,hat there is no special requirement for initialization of this synchronizer.
When any process starts pulse I, within D t,ime units all other processes will also
start pulse 1. Therefore, the complexity of initializing the simple synchronizer is
đang được dịch, vui lòng đợi..
