Created
September 12, 2018 20:39
-
-
Save hadhi631/95e4c971233b49777c59226661224176 to your computer and use it in GitHub Desktop.
sync2mutex
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
@implementation TestMutex { | |
NSObject *mutex_1; | |
NSObject *mutex_2; | |
} | |
- (instancetype)init { | |
if (self = [super init]) { | |
mutex_1 = [NSObject new]; | |
mutex_2 = [NSObject new]; | |
} | |
return self; | |
} | |
// Thread A and Thread B will be calling this and will not block | |
// Thread C and Thread D from calling secondMethod | |
- (void)firstMethod { | |
@synchronized(mutex_1) { | |
// Deals with Resource 1 | |
} | |
} | |
// Thread C and Thread D will be calling this and will not block | |
// Thread A and Thread B from calling firstMethod | |
- (void)secondMethod { | |
@synchronized(mutex_2) { | |
// Deals with Resource 2 | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment