Skip to content

Commit b36478f

Browse files
authored
clarify paragraph in "On using std::sync::Mutex and tokio::sync::Mutex" (#836)
Regarding to how the synchronous and asynchronous `Mutex` behave with the executor.
1 parent 218ad62 commit b36478f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

content/tokio/tutorial/shared-state.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ from within async code. An async mutex is a mutex that is locked across calls
9898
to `.await`.
9999

100100
A synchronous mutex will block the current thread when waiting to acquire the
101-
lock. This, in turn, will block other tasks from processing. However, switching
102-
to `tokio::sync::Mutex` usually does not help as the asynchronous mutex uses a
103-
synchronous mutex internally.
101+
lock. This, in turn, will block other tasks from processing. Switching
102+
to `tokio::sync::Mutex` will cause the task to yield control back to the
103+
executor, but this will usually not help with performance as the asynchronous
104+
mutex uses a synchronous mutex internally.
104105

105106
As a rule of thumb, using a synchronous mutex from within asynchronous code is
106107
fine as long as contention remains low and the lock is not held across calls to

0 commit comments

Comments
 (0)