A Race Condition Can Present a Problem

Consider the following possibility:

  1. The task executing on processor 0 reads the semaphore to determine the buffer's availability.

  2. The task tests the semaphore's value and determines that the buffer is available (the semaphore value = zero).

  3. Immediately after the task on processor 0 has completed the memory read to obtain and test the state of the semaphore value, a task executing on processor 1 has initiated a memory read request on the FSB to test the state of the same semaphore. It completes the read and begins testing the value.

  4. The processor 0 task initiates a memory write on the FSB to update the semaphore to a non-zero value to mark the shared buffer as unavailable. After it completes the write, it considers itself the sole owner of the buffer.

  5. The processor 1 task also determined the buffer is available and it now performs a memory write on the FSB to update the semaphore to a non-zero value to mark the shared buffer as unavailable. It completes the write and it also now considers itself the sole owner of the buffer.

Two tasks executing on two separate processors now each believe that they have exclusive ownership of the buffer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.178.133