async-rs / async-rs/async-std

Highlight differences of async_std::sync::Mutex and std::sync::Mutex in the docs

Open
#726 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
4.1k
Forks
339
PR merge metrics
No merged PRs in 30d

Description

I have the following question regarding async_std::sync::Mutex and thought it might be a good addition to clarify it in the docs (if my question is valid / I am new to Rust).

Can the async_std::sync::Mutex be used in a single thread to synchronise a sequence of awaits? For example:

```
async fn read_at(pos) {
// make sure concurrent calls to test read at the correct position
let file = file_mutex.lock().await;
file.seek(pos).await;
file.read(...).await;
}
```

The std::sync::Mutex docs say `lock()` may panic when already locked from the same thread. However, for single threaded async/await code it may make sense to allow this.

If this is not possible is there a lock with this behaviour?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.