Shared Output
Last updated
Last updated
From the introduction, mutual exclusion restricts only one process to enter a critical section.
process-1.c
and process-2.c
are two processes that need to display their outputs on the standard error. To ensure the output is right, these two processes should access the standard error exclusively. That is to say, one process should wait until the other process occupying the standard error finishes its display. Otherwise, the output may be confusing as shown in the figure. We can use semaphore to ensure mutual exclusion. The result is shown in figure 2.
Comment out semaphore-related codes, run these two programs (proc-1.c
, proc-2.c
) and see what happens.