Multithreading – are semaphore P and V operations atomic?
•
Java
Are the P () and V () operations that can be performed on semaphores atomic? Can semaphores prevent two processes from entering P ()?
Solution
Suppose we have a binary semaphore s with a value of 1, and two processes try to execute P on at the same time Only one operation can be completed before the next V operation; Other processes attempting to perform the P operation are paused
From my college notes:
Semaphores can solve the problems of mutual exclusion and conditional synchronization So the answer to your question is: Yes
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码