Is there something opposite to Semaphore
Is there something opposite to Semaphore? I am looking for something system-wide process-independant that I could use to count how much threads are 开发者_C百科using a resource, and not so much limit how much threads are using a resource. Or should I consider using a semaphore with a pretty high maximum count?
Semaphores can be released or acquired in any order. I would recommend that you simply release the semaphore when your thread starts using the resource and acquire it when done with the resource.
This is assuming you need cross-process communication. If you don;t, by all means use a counter variable.
May I ask why you're doing this?
精彩评论