GithubHelp home page GithubHelp logo

anlock's People

Contributors

springox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

davidhuang85

anlock's Issues

Look 4 detailed questions in the content field.

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~

Atomic test case is wrong

@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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.