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 { | |
dispatch_semaphore_t sem; | |
dispatch_queue_t queue_1; | |
dispatch_queue_t queue_2; | |
dispatch_queue_t queue_3; | |
dispatch_queue_t queue_4; | |
} | |
- (instancetype)init { | |
if (self = [super init]) { |
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]; | |
} |
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 | |
- (void)firstMethod { | |
@synchronized(self) { | |
// Your code here | |
} | |
} | |
- (void)secondMethod { | |
@synchronized(self) { |
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 { | |
NSRecursiveLock *recLock; | |
} | |
- (instancetype)init { | |
if (self = [super init]) { | |
// Initialize the mutex | |
recLock = [[NSRecursiveLock alloc] init]; | |
} |
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 { | |
BOOL isProcessing; | |
NSLock *lock; | |
} | |
- (instancetype)init { | |
if (self = [super init]) { | |
// Initialize the mutex | |
isProcessing = YES; |
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 <pthread/pthread.h> | |
@implementation TestMutex { | |
pthread_mutex_t mutex; | |
} | |
- (instancetype)init { | |
if (self = [super init]) { | |
// Initialize the mutex |
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
p.firstName = @"Saddham"; | |
p.lastName = @"Hussain"; | |
NSString *fullName_2 = [p fullName]; |
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
p.firstName = @"Jack"; | |
p.lastName = @"Daniel"; | |
NSString *fullName_1 = [p fullName]; |
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 Person : NSObject | |
@property(copy) NSString *firstName; | |
@property(copy) NSString *lastName; | |
- (NSString *)fullName; | |
@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
static inline void reallySetProperty(id self, SEL _cmd, id newValue, | |
ptrdiff_t offset, bool atomic, bool copy, bool mutableCopy) | |
{ | |
id oldValue; | |
id *slot = (id*) ((char*)self + offset); | |
if (copy) { | |
newValue = [newValue copyWithZone:NULL]; | |
} else if (mutableCopy) { | |
newValue = [newValue mutableCopyWithZone:NULL]; |