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

Lock tokio::sync::Mutexfrom synchronous code #4109

Closed
dpc opened this issue Sep 14, 2021 · 5 comments
Closed

Lock tokio::sync::Mutexfrom synchronous code #4109

dpc opened this issue Sep 14, 2021 · 5 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue. M-sync Module: tokio/sync

Comments

@dpc
Copy link
Contributor

dpc commented Sep 14, 2021

Is your feature request related to a problem? Please describe.
I need to use async Mutex (because I need to lock between async yield points), but at the same time I need to share (and lock) it from some synchronous code.

Describe the solution you'd like
lock_blocking method on Mutex (and corresponding on RwLock) that allow locking the mutex from synchronous code.

Describe alternatives you've considered
Maybe there's a library that can do it already? I'm having trouble finding it though.

@dpc dpc added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Sep 14, 2021
@Darksonn Darksonn added the M-sync Module: tokio/sync label Sep 14, 2021
@Darksonn
Copy link
Contributor

You can do this by calling futures::executor::block_on(mutex.lock()), though it could still make sense to add this. We have something similar for the mpsc channel.

@Darksonn Darksonn added E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue. labels Sep 19, 2021
@hi-rustin
Copy link
Contributor

I am working on this.

@hi-rustin
Copy link
Contributor

@dpc Can we close this issue now?

@taiki-e taiki-e closed this as completed Sep 25, 2021
@Darksonn
Copy link
Contributor

Oh, I didn't notice that the PR didn't include a keyword to auto-close it.

@LeonarddeR
Copy link

LeonarddeR commented Aug 16, 2022

Note that in the initial comment of this issue, equivalent synchronous methods were requested for RwLock. This wasn't covered by #4130 but #4425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue. M-sync Module: tokio/sync
Projects
None yet
Development

No branches or pull requests

5 participants