Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispatch_once_t cannot be an instance variable #315

Closed
steipete opened this issue Feb 6, 2017 · 1 comment
Closed

dispatch_once_t cannot be an instance variable #315

steipete opened this issue Feb 6, 2017 · 1 comment

Comments

@steipete
Copy link
Contributor

steipete commented Feb 6, 2017

BOXAPIMultipartToJSONOperation.m uses dispatch_once_t as an instance variable which does not work.

https://github.com/box/box-ios-sdk/blob/master/BoxContentSDK/BoxContentSDK/Operations/BOXAPIMultipartToJSONOperation.m#L368

This StackOverflow question is a surprisingly good an thorough analysis why this doesn't work:
http://stackoverflow.com/questions/13856037/can-i-declare-dispatch-once-t-predicate-as-a-member-variable-instead-of-static/19845164#19845164

Greg Parker, who works on the Objective-C Runtime at Apple.

dispatch_once_t must not be an instance variable. The implementation of dispatch_once() requires that the dispatch_once_t is zero, and has never been non-zero. The previously-not-zero case would need additional memory barriers to work correctly, but dispatch_once() omits those barriers for performance reasons.

Xcode 8.3 Beta 1 now has a new Analyzer Warning step which we found while working on Box integration for PSPDFKit's PDF Viewer for iOS: https://pdfviewer.io

screen shot 2017-02-06 at 22 53 52

I'll follow up with a PR that fixes this.

@boxtcarpel
Copy link
Contributor

Thanks, @steipete! Nice catch.

steipete added a commit to PSPDFKit-labs/box-ios-sdk that referenced this issue Feb 6, 2017
Fixes box#315.

CLA is signed.

Signed-off-by: Peter Steinberger <steipete@gmail.com>
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

No branches or pull requests

2 participants