Below is a list of errors that have been found in previous attempted solutions
to this programming problem. Avoid these errors.
- ERROR: a delay of the form:
for (i=0; i < delay; i++) sched_yield();
is added to a program to "fake" synchronization. The program produces
incorrect output if the line of code of removed. Neither adding nor
removing delays should affect the correctness of the program.
- ERROR: A user thread finds that the buffer it has chosen is not available
so it just "gives up" and employs the other buffer instead. The user is
required to participate in a synchronization protocol that enables it to
wait for a turn to use the buffer that was its first choice.
- ERROR: The program employs busy waiting for synchronization. For example
a loop of the form:
"while (some flag is false) do nothing"
This is very bad. The waiting process wastes CPU time. It tends to
prolong the waiting time by preventing other processes from getting the
CPU and changing the value of the flag.
- ERROR: The program uses a flag for synchronization but the flag is not
protected with a semaphore. Any flag that is used by more than one
thread is a shared variable. It isn't likely that shared variables can
be used correctly without protection.
- ERROR: A thread that locks too much data is probably wrong. For example
suppose a user thread blocks access to both buffers while using only one
of the buffers. That is inefficient. On a multiprocessor it should be
possible for two buffers to be in use at the same time. The program
should allow it.