Skip to content

Instantly share code, notes, and snippets.

@boredzo
Created April 20, 2012 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boredzo/2425324 to your computer and use it in GitHub Desktop.
Save boredzo/2425324 to your computer and use it in GitHub Desktop.
dispatch_once is not reentrant
#import <Foundation/Foundation.h>
static void test(void);
int main(int argc, char **argv) {
@autoreleasepool {
test();
NSLog(@"Test succeeded");
}
return EXIT_SUCCESS;
}
static void test(void) {
static unsigned count = 0;
NSLog(@"Attempting test (%u)...", ++count);
static dispatch_once_t token;
dispatch_once(&token, ^{
test();
});
--count;
}
CC=clang
CFLAGS+=-std=c99 -g
LDFLAGS+=-framework Foundation
dispatch_once_reentrancy_test: dispatch_once_reentrancy_test.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment