Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ck_dec spinlock can acquire the already-acquired lock. #99

Closed
multics69 opened this issue Jun 6, 2017 · 4 comments
Closed

ck_dec spinlock can acquire the already-acquired lock. #99

multics69 opened this issue Jun 6, 2017 · 4 comments

Comments

@multics69
Copy link

multics69 commented Jun 6, 2017

ck_dec spinlock can acquire the lock that is already acquired. You can reproduce the problem using the following code snippet, which is modified from ck/regressions/ck_spinlock/validate/validate.h. The underflow of lock->value at ck_spinlock_dec_lock_eb() is the root cause of the problem.

======= code to reproduce =======

LOCK_DEFINE;

int
main(int argc, char *argv[])
{
#ifdef LOCK_INIT
        LOCK_INIT;
#endif
#ifdef LOCK_STATE
        LOCK_STATE;
#endif
        printf("[1] try to acquite the lock\n");
        LOCK;
        printf("[2] the lock is acquired\n");

        printf("[3] try to acquite the lock\n");
        LOCK;
        printf("[4] the lock is acquired\n");
        return (0);
}

======= output =======

[1] try to acquite the lock
[2] the lock is acquired
[3] try to acquite the lock
[4] the lock is acquired
@sbahra
Copy link
Member

sbahra commented Jun 10, 2017

Thanks for the PR! This is specific to lock_eb, specifically, since we don't busy-wait after lock_eb, the number of decrement operations is always unbounded. This is now fixed in master. Note the core algorithm has no guarantees on bound (in case of extreme starvation, underflow is still possible but it's very unlikely to occur).

@sbahra sbahra closed this as completed Jun 10, 2017
@multics69
Copy link
Author

Thank you!

@sbahra
Copy link
Member

sbahra commented Jun 12, 2017

Out of curiosity, what are you working on? Always love to hear about use-cases / research.

@multics69
Copy link
Author

I am working on developing a performance profiler to find spinlock contention. Since concurrency kit already has all sort of spinlocks with great unit test cases, I am using CK for unit test cases of my performance profiler. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants