Skip to content

Conversation

@ndkoval
Copy link
Member

@ndkoval ndkoval commented Nov 11, 2021

No description provided.

@ndkoval ndkoval requested a review from qwwdfsad November 11, 2021 15:46
@ndkoval
Copy link
Member Author

ndkoval commented Nov 11, 2021

Only those tests that require Mutex.onLock() fail -- this will be fixed with new select implementation.

Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, you can reuse nom-intrusive implementation of onLock: 7755edb#diff-86e8b6879026f347540a4b86b2c594fe25128a0fb168cc0689ef48008c8b4d5fR99

@ndkoval
Copy link
Member Author

ndkoval commented Nov 19, 2021

@qwwdfsad I already have a proper implementation with new select API

Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see that the build is failing, please make it pass. You can temporary ignore onLock tests for that sake.

My biggest concern here is the relevance of the PR -- could you please elaborate on the purpose of the PR? What benefits does it bring?

affected._state.compareAndSet(this, update)
override fun resume(value: Unit, onCancellation: ((cause: Throwable) -> Unit)?) {
this@MutexImpl.owner.value = owner
cont.resume(value, onCancellation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if this resume will have no effect, e.g. because the continuation was concurrently cancelled?

* Use [yield] or [CoroutineScope.isActive] to periodically check for cancellation in tight loops if needed.
*
* Use [tryLock] to try acquiring a lock without waiting.
* This function can be used in [select] invocation with [onLock] clause.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is irrelevant as onLock is being deprecated for removal

) : CancellableContinuation<Unit> by cont {
override fun tryResume(value: Unit, idempotent: Any?, onCancellation: ((cause: Throwable) -> Unit)?): Any? {
val token = cont.tryResume(value, idempotent, onCancellation)
if (token !== null) this@MutexImpl.owner.value = owner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment why it is safe to have a race here -- the continuation can be already executing and even invoking unlock while owner is not set

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot be executing before completeResume(..)

override fun toString(): String = "Empty[$locked]"
}
internal class MutexImpl(locked: Boolean) : SemaphoreImpl(1, if (locked) 1 else 0), Mutex {
private val owner = atomic<Any?>(if (locked) null else NO_OWNER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document possible state transitions here and their purpose

@ndkoval
Copy link
Member Author

ndkoval commented Jan 11, 2022

Thanks for the review -- I have fixed and clarified everything in #3020

@ndkoval ndkoval closed this Jan 11, 2022
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.

3 participants