Skip to content

Mutex.withLock uses owner parameter for checks but doesn't state equality contract in docs #940

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
baltiyskiy opened this issue Jan 16, 2019 · 3 comments
Labels
docs KDoc and API reference

Comments

@baltiyskiy
Copy link

baltiyskiy commented Jan 16, 2019

Mutex.withLock() states that owner is an "optional owner token for debugging". However, it really uses it for consistency checks, e.g. curOwner !== owner in lockSuspend. This means that owner must be unique for each invocation of withLock(), otherwise one will get a cryptic IllegalStateException: Already locked by <owner>. The problem is that this contract isn't stated in the docs. Another problem is that using a debugging token for consistency checks doesn't look like a good idea.

@elizarov
Copy link
Contributor

So what change do you propose to make?

@baltiyskiy
Copy link
Author

baltiyskiy commented Jan 16, 2019

Either update the docs to state that owner must be unique for each concurrent invocation, or don't use it for consistency checks.

There are cases where "debugging token" is naturally derived from the operation that wants to take the lock, but its description can be non-unique. One might say that this is a problem with debugging, but in fact logging might use some other means to provide context, e.g. coroutines-aware context propagation.

@qwwdfsad qwwdfsad added the docs KDoc and API reference label Jan 16, 2019
@qwwdfsad
Copy link
Collaborator

This means that owner must be unique for each invocation of withLock()

It does not. It should be unique for overlapping concurrent operations.

Either update the docs to state that owner must be unique for each concurrent invocation

Actually, withLock was the only method where this limitation has not been noticed

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

No branches or pull requests

3 participants