| ... | @@ -18,10 +18,11 @@ | ... | @@ -18,10 +18,11 @@ |
| 18 | //! } | 18 | //! } |
| 19 | //! | 19 | //! |
| 20 | //! fn producer() void { | 20 | //! fn producer() void { |
| 21 | //! m.lock(); | 21 | //! { |
| 22 | //! defer m.unlock(); | 22 | //! m.lock(); |
| 23 | //! | 23 | //! defer m.unlock(); |
| 24 | //! predicate = true; | 24 | //! predicate = true; |
| | 25 | //! } |
| 25 | //! c.signal(); | 26 | //! c.signal(); |
| 26 | //! } | 27 | //! } |
| 27 | //! | 28 | //! |
| ... | @@ -37,7 +38,7 @@ | ... | @@ -37,7 +38,7 @@ |
| 37 | //! thread-1: condition.wait(&mutex) | 38 | //! thread-1: condition.wait(&mutex) |
| 38 | //! | 39 | //! |
| 39 | //! thread-2: // mutex.lock() (without this, the following signal may not see the waiting thread-1) | 40 | //! thread-2: // mutex.lock() (without this, the following signal may not see the waiting thread-1) |
| 40 | //! thread-2: // mutex.unlock() (this is optional for correctness once locked above, as signal can be called without holding the mutex) | 41 | //! thread-2: // mutex.unlock() (this is optional for correctness once locked above, as signal can be called while holding the mutex) |
| 41 | //! thread-2: condition.signal() | 42 | //! thread-2: condition.signal() |
| 42 | //! ``` | 43 | //! ``` |
| 43 | | 44 | |