Does anyone know how semaphores in multiprocessing systems are synchronized? When you have several physical processors in a symmetric multiprocessing system, semaphores are used to keep several processes from entering a critical region at once. What I'm wondering is, how are the V(s) and P(s) operations actually implemented? While these operations are carried out in a single cycle to prevent synchronization problems, I don't understand how the situation is handled if two processes execute a P(s) in exactly the same cycle. Wouldn't the same synchronization problems manifest themselves? By its very nature, the P operation involves a fetch and a write. If two processors execute a P(s) in the same clock cycle, wouldn't it be possible for both to fetch the data, and then for both to write the data, and then both enter the critical region? Obviously this problem has been circumvented somehow, but how? How does one processor lock out other processors from the semaphore between the fetch and the write operation? I'm assuming the solution involves some specialized low-level circuitry, but how is it done?
