开发者

Semaphore accessed by few processes concurently

开发者 https://www.devze.com 2023-02-14 20:44 出处:网络
Is it ok if 开发者_StackOverflowfew/couple of processes access semaphore concurently or semaphore should be accesed mutualy exclusive?Well, that\'s the purpose of semaphore - to be safely accessible f

Is it ok if 开发者_StackOverflowfew/couple of processes access semaphore concurently or semaphore should be accesed mutualy exclusive?


Well, that's the purpose of semaphore - to be safely accessible from several threads. Actually, how would you implement mutual exclusion? Having a semaphore with max value 1 is the easiest way. Semaphores are conceptually the very basic synchronization mechanism and they are meant to be used concurrently.

Behind the scenes the internal counter in the semaphore must be synchronized, but that should be addressed by e.g. the operating system. Accessing semaphore is inherently thread-safe.

0

精彩评论

暂无评论...
验证码 换一张
取 消