| ... | ... | @@ -18,10 +18,11 @@ |
| 18 | 18 | //! } |
| 19 | 19 | //! |
| 20 | 20 | //! fn producer() void { |
| 21 | | //! m.lock(); |
| 22 | | //! defer m.unlock(); |
| 23 | | //! |
| 24 | | //! predicate = true; |
| 21 | //! { |
| 22 | //! m.lock(); |
| 23 | //! defer m.unlock(); |
| 24 | //! predicate = true; |
| 25 | //! } |
| 25 | 26 | //! c.signal(); |
| 26 | 27 | //! } |
| 27 | 28 | //! |
| ... | ... | @@ -37,7 +38,7 @@ |
| 37 | 38 | //! thread-1: condition.wait(&mutex) |
| 38 | 39 | //! |
| 39 | 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 | 42 | //! thread-2: condition.signal() |
| 42 | 43 | //! ``` |
| 43 | 44 | |