Among the various ways to enter critical sections, semaphores and mutexes are the most popular.
A semaphore is a waiting mechanism, and a mutex is a blocking mechanism, well, the concept as a whole is confusing, but, in short, a thread that activates a mutex can deactivate it. with that in mind ...
Do not allow any process to block a partial amount of resources, if the process requires 5 resources, wait until all of them are available.
- If you use the semaphore here, you can unlock / disable the resource occupied by another thread. by this I mean that prevention is another reason.
These 2 are basic conditions for me, the remaining 2 of the 4 general precautions may be associated with them.
If you do not agree with ps, add comments. I already finished gtg, later I will add a cleaner and more clear explanation.
source share