Last active
March 27, 2017 15:42
-
-
Save soxjke/1275e069f938f12fd666d67ec397f736 to your computer and use it in GitHub Desktop.
RaceCondition2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thread 5Queue : com.apple.root.user-initiated-qos (concurrent) | |
#0 0x000000010f181d2b in objc_release () | |
#1 0x000000010f1831d1 in (anonymous namespace)::AutoreleasePoolPage::pop(void*) () | |
#2 0x00000001125037ce in _dispatch_root_queue_drain () | |
#3 0x0000000112503059 in _dispatch_worker_thread3 () | |
#4 0x00000001128cb4de in _pthread_wqthread () | |
#5 0x00000001128c9341 in start_wqthread () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface StringContainer : NSObject | |
@property (nonatomic, strong) NSString *string; | |
- (instancetype)initWithString:(NSString *)string; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "StringContainer.h" | |
@implementation StringContainer | |
- (instancetype)initWithString:(NSString *)string { | |
self = [super init]; | |
if (self) { | |
self.string = string; | |
} | |
return self; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@class StringContainer; | |
@interface Test : NSObject | |
@property (nonatomic, strong) StringContainer *stringProp; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Test.h" | |
#import "StringContainer.h" | |
@interface Test() { | |
StringContainer *_stringProp; | |
} | |
@end | |
@implementation Test | |
- (void)setStringProp:(StringContainer *)stringProp { | |
[_stringProp autorelease]; | |
_stringProp = [stringProp retain]; | |
} | |
- (StringContainer *)stringProp { | |
return _stringProp; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ViewController () | |
@property (nonatomic, strong) Test *test; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[self testCrash]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)testCrash { | |
self.test = [Test new]; | |
for(int i = 0; i < 1000; i++) { | |
dispatch_async(dispatch_get_global_queue(0, 0), ^() { | |
self.test.stringProp = [[StringContainer alloc] initWithString:[[NSString alloc] initWithFormat:@"%d", i]]; | |
}); | |
dispatch_async(dispatch_get_global_queue(0, 0), ^() { | |
[self print:self.test.stringProp]; | |
}); | |
} | |
} | |
- (void)print:(StringContainer * __unsafe_unretained)string { | |
NSLog(@"%@", string.string); | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment