开发者

Semaphore accessed by few processes concurently

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜