Skip to content

Add Mutex.holdsLock #92

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

Closed
wants to merge 1 commit into from
Closed

Conversation

fvasco
Copy link
Contributor

@fvasco fvasco commented Jul 26, 2017

No description provided.

@elizarov
Copy link
Contributor

Have you considered following the pattern of Thread.holdLock(). That is, instead of providing checkLockOwner method, provide a more general isLockOwner method (or maybe call it holdsLock), and let client code be written as check(lock.holdsLock(owner))?

@elizarov
Copy link
Contributor

Also, since the implementation is not straightforward, a test for this method's operation in different circumstances is needed, too (you can add it to MutexTest)

@fvasco
Copy link
Contributor Author

fvasco commented Jul 28, 2017

Have you considered following the pattern of Thread.holdLock()

Yes, I did, this is an interesting question.

Thread.holdLock() is specific indeed for debugging purpose in conjunction with assert keyword. Unfortunately Kotlin doesn't provides an adeguate replacement so, in my initial choice, I preferred to not expose any debug information and to provide only the required functionality.

However the holdLock is clearly more versatile, if you consider it preferreable then I apply the change.

In order to cover all use case, in your opinion what are the useful use cases??

@elizarov
Copy link
Contributor

I don't have any specific use-cases for holdsLock beyond debugging via check(lock.holdsLock(owner)). It just looks more explicit to use it as a part of check(...) expression that I use for my preconditions, than a method named with check.

@fvasco
Copy link
Contributor Author

fvasco commented Jul 28, 2017

To debugging purpose we should consider to provide an inspection method to understand "what" locks a mutex, in the current implementation this issue is resolved throwing an exception with description template: "Mutex is locked by ${state.owner} but expected $owner"

However this use case can be nicely covered providing a complete toString() implementation

@fvasco fvasco changed the title Add Mutex.checkLockOwner Add Mutex.holdsLock Jul 29, 2017
@elizarov
Copy link
Contributor

Merged

@elizarov elizarov closed this Aug 16, 2017
@elizarov
Copy link
Contributor

elizarov commented Aug 18, 2017

Released in version 0.18

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

Successfully merging this pull request may close these issues.

2 participants