| 20 | bool processed = false; |
| 21 | |
| 22 | task<void> worker_thread() { |
| 23 | // Wait until main() sends data |
| 24 | co_await m.lock(); |
| 25 | co_await cv.wait(m, [] { return ready; }); |
| 26 | |
| 27 | // after the wait, we own the lock. |
| 28 | std::cout << "Worker thread is processing data\n"; |
| 29 | data += " after processing"; |
| 30 | |
| 31 | // Send data back to main() |
| 32 | processed = true; |
| 33 | std::cout << "Worker thread signals data processing completed\n"; |
| 34 | |
| 35 | // Manual unlocking is done before notifying, to avoid waking up |
| 36 | // the waiting thread only to block again (see notify_one for details) |
| 37 | m.unlock(); |
| 38 | cv.notify_one(); |
| 39 | } |
| 40 | |
| 41 | task<> main_thread() { |
| 42 | data = "Example data"; |
no test coverage detected