Friday, December 18, 2009

17.8 Packet Communication, Broadcast and Barriers



[ Team LiB ]






17.8 Packet Communication, Broadcast and Barriers


Once the dispatcher handles multiple simultaneous tasks, implement the handling of the BROADCAST and BARRIER packets. The child tasks now have to communicate with the dispatcher in packet format so that the dispatcher and its tasks can distinguish control information (broadcast or barrier) from data information.


When the dispatcher receives a BROADCAST request from standard input, it forwards the packet on the writefd descriptors for each task whose computation ID matches that of the BROADCAST packet. If the dispatcher receives a BROADCAST request from one of the readfd descriptors, it forwards the packet on the writefd descriptors for each task whose computation ID matches that in the BROADCAST packet. Since, in a future extension, tasks from the computation may reside on other hosts, the dispatcher also forwards the packet on its standard output.


When the dispatcher receives a BARRIER packet from a task, it sets the barrier member for that task to the barrier number specified by the packet data. When all the tasks in a computation have reported that they are waiting for the barrier, the dispatcher sends a BARRIER message on standard output.


When the dispatcher reads a BARRIER packet for that barrier number from standard input, it resets the barrier member to �1 and sends a SIGUSR1 signal to all the tasks in the computation. The BARRIER packet from standard input signifies that all tasks in the computation are waiting at the designated barrier and that they can be released. Assume that the dispatcher never receives a second BARRIER packet from standard input before it has forwarded a corresponding BARRIER packet on standard output.


Implement the barrier on the task side by blocking the SIGUSR1 signal, writing a BARRIER packet to standard output, and then executing sigsuspend in a loop until the SIGUSR1 signal arrives. Example 8.26 shows how this is done.


Write a dummy task program to generate appropriate broadcast and barrier messages.



Exercise 17.10

What complications do BROADCAST packets present from a synchronization point of view?


Answer:


Since BROADCAST packets may have to be forwarded to other tasks, the input and output threads now share the writefd descriptor associated with those tasks.







    [ Team LiB ]



    No comments: