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

Mutex.withoutLock #527

Closed
clarfonthey opened this issue Sep 4, 2018 · 2 comments
Closed

Mutex.withoutLock #527

clarfonthey opened this issue Sep 4, 2018 · 2 comments

Comments

@clarfonthey
Copy link

clarfonthey commented Sep 4, 2018

I find myself doing this pattern a lot:

mutex.withLock {
    someWork()

    mutex.unlock()
    try {
        someOtherWork(channel.receive())
    } finally {
        mutex.lock()
    }

    someMoreWork()
}

In the case of a regular Lock, I'd use a condition variable, which will automatically relinquish the lock. Unfortunately, for this case, I can't do that. It'd be nice to have a mutex.withoutLock { ... } or equivalent for this case.

@elizarov
Copy link
Contributor

elizarov commented Sep 5, 2018

Why are you using a Mutex in the first place? What is your use-case?

@penn5
Copy link

penn5 commented Feb 26, 2020

This would be incredibly useful to me. For example, using recursive functions. IMO this should just be an inline function equating the the code sample in the OP. AFAIK there is no better alternative than Mutex for this use case, unless a reentrant lock is added (which was previously rejected in #1686).

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

No branches or pull requests

3 participants