springox / anlock Goto Github PK
View Code? Open in Web Editor NEWA ReadWrite Lock with Objective-C, and Performance Test for different lock schemes.
License: Apache License 2.0
A ReadWrite Lock with Objective-C, and Performance Test for different lock schemes.
License: Apache License 2.0
1.What's the exact difference between ANReadWriteLock & ANRecursiveRWLock
We could c the difference in performance but what's the exact difference in usage? And what's the former cannot do but the latter can especially?
2.We can take advantage of a handful of example code 2 test if an interface which implements NSCoding protocol do satisfy the recursive lock.
// NSRecursiveLock *lock = [[NSRecursiveLock alloc] init];
ANRecursiveRWLock *lock = [[ANRecursiveRWLock alloc] init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
static void (^RecursiveMethod)(int);
RecursiveMethod = ^(int value) {
[lock lock];
if (value > 0) {
NSLog(@"value = %d", value);
sleep(2);
RecursiveMethod(value - 1);
}
[lock unlock];
};
RecursiveMethod(5);
});
If u employ the ANRecursiveRWLock instead of NSRecursiveLock which comes from OC, u'd be aware of that it's gonna be deadlocked.
As we all no, a write operation cannot b disturbed by a read operation as the logic in the code.
But could u declare what's the meaning of recursive lock on earth?
3Q in advance~
@property (atomic, assign) int atomicFlag;
//Atomic Flag
timeBefore = CFAbsoluteTimeGetCurrent();
for(i=0; i<count; i++){
self.atomicFlag = 1;
}
timeCurrent = CFAbsoluteTimeGetCurrent();
printf("Atomic Set/Get used : %f\n", timeCurrent-timeBefore);
For atomic test case, set the same value to non copy property
does not trigger any lock. It just simply return. So the lock performance for atomic
is totally wrong. You should change the test code to this:
@property (atomic, assign) NSUInteger atomicFlag;
self.atomicFlag = count;
See objective-c runtime source code for property setter:
objc-accessor source code
下载下来文件是损坏的亲
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.