Skip to content

Remove redundant OSMemoryBarrier from CFBundle.c - #5382

Open
AZero13 wants to merge 1 commit into
swiftlang:mainfrom
AZero13:sync
Open

Remove redundant OSMemoryBarrier from CFBundle.c#5382
AZero13 wants to merge 1 commit into
swiftlang:mainfrom
AZero13:sync

Conversation

@AZero13

@AZero13 AZero13 commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

When a bundle is unique, it is allocated and initialized on the current thread and returned to the same thread.

Since the pointer isn't published to any other thread, no memory barrier is needed to ensure initialization visibility.

If the bundle is not unique, the code immediately acquires CFBundleGlobalDataLock.

If a user passes the bundle pointer to another thread in a way that leads to races, that is a bug with the user, and their problem.

When a bundle is unique, it is allocated and initialized on the current thread and returned to the same thread.

Since the pointer isn't published to any other thread, no memory barrier is needed to ensure initialization visibility.

If the bundle is not unique, the code immediately acquires CFBundleGlobalDataLock.

If a user passes the bundle pointer to another thread in a way that leads to races, that is a bug with the user, and their problem.
@parkera

parkera commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Hm, I need to think back to why we introduced this in the first place. The comment suggests it was not safe to use with dispatch_once otherwise, but it may be outdated.

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.

2 participants