We compare the three alternatives in a ping-pong
test: we make the slave wait for the master and the master ``signals'' the
slave; next the master wait for the slave and the slave ``signals'' the master
. We measure the number of cycles on the master to get the whole job
done. Figure may help in understanding the ping-pong test.
Moreover each synchronization method must ensure that:
The synchronization variable method fulfills the previous requirements. For IPC and Threads semaphores we must use 2 semaphores4 each one indicates when the master and slave are ready to enter in parallel section; the ping-pong is done with 2 barriers that act like this:
Experiments are realized on a dual PII 400 and the time measurement is
done using the time stamp counter5 (tsc)
of Intel Pentium processors, we suppose that the tsc of each processor holds
roughly the same value. Results are presented figure : for
each method we make 1000 runs and presents the smallest, average and largest
time for ping-pong. These results show that synchronization variable is by far the
fastest method. As we said previously the difference between synchronization
variable and the 2 other methods is that the slave process is ready and
running so synchronization does not pay the cost of a system call and moving process from the wait/suspend queue to the
running queue.
On the other hand having an active slave may interfere with other
multi-threaded library.