Skip to content

use GCD semaphores on macOS - #11

Open
zdAlexM wants to merge 2 commits into
halon:masterfrom
zdAlexM:alexm/gcd-semaphores
Open

use GCD semaphores on macOS#11
zdAlexM wants to merge 2 commits into
halon:masterfrom
zdAlexM:alexm/gcd-semaphores

Conversation

@zdAlexM

@zdAlexM zdAlexM commented Jan 20, 2026

Copy link
Copy Markdown

On modern macOS, POSIX semaphores are unsupported. The API exists but always returns errno. Per a Stack Overflow solution, one can use Grand Central Dispatch as a drop-in replacement.

@eriklax eriklax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the latest change, this doesn't merge correctly with counter being moved up with error condtions.

@zdAlexM
zdAlexM force-pushed the alexm/gcd-semaphores branch from 82e2174 to 774f023 Compare July 28, 2026 16:40
@zdAlexM

zdAlexM commented Jul 28, 2026

Copy link
Copy Markdown
Author

we moved the counter back down so it doesn't have to be duplicated in each ifdef, and also allows for distinguishing which part failed, the semaphor or the counter mmap.

@dfateyev

Copy link
Copy Markdown
Contributor

Unlike POSIX semaphores with MAP_SHARED and pshared=1, GCD semaphores don't support fork() which is used there, so you would loose sync with children.
You may use a named semaphore and sem_open() which works with forking correctly and presents in macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants