1

As far as I've understood, there is no way at all to get unnamed semaphores under (at the last versions of) OS X. I have to specify a string with a name. This sounds so unreasonable to me. Why in the world one wouldn't want to support just.. semaphores?

Say that I really need to create some set of semaphores. Say an array (but I don't have a simple way to number them). How can I get that? Do I really have to use sprintf to build up semaphores? Isn't there any more elegant way?

Matteo Monti
  • 8,362
  • 19
  • 68
  • 114
  • No system I know of has unnamed semaphores. The naming might be different - they might be strings, like OS X, or ID-named like Posix, but they are still named. I do not understand the frustration. – SergeyA Aug 21 '15 at 18:44
  • 1
    @SergeyA: Do you know Linux, Unix, VMS, or MSWindows? All of those have unnamed semaphores. – wallyk Aug 21 '15 at 18:53
  • I know those systems, and semaphores there are named. Those names are ids. – SergeyA Aug 21 '15 at 19:02
  • What are you actually trying to achieve? – gnasher729 Aug 21 '15 at 19:13

1 Answers1

1

You should be able to use an array of Grand Central Dispatch semaphores.

This question also may be a duplicate.

Community
  • 1
  • 1
jwde
  • 642
  • 4
  • 13
  • Depending on why you're using semaphores, you might also consider NSCondition, which IIRC can basically become a semaphore by adding a couple of lines of extra code to check the value and go back to sleep if necessary. – dgatwood Aug 23 '15 at 04:45
  • Of course, if you need to use the semaphores across process boundaries, then neither of those approaches will work, and the only options are named POSIX semaphores or SysV semaphores. I'm assuming that this is probably not the case, though. – dgatwood Aug 23 '15 at 04:45