MCPcopy Create free account
hub / github.com/Codesire-Deng/co_context / worker_thread

Function worker_thread

example/cv_notify_one.cpp:22–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20bool processed = false;
21
22task<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
41task<> main_thread() {
42 data = "Example data";

Callers 1

mainFunction · 0.85

Calls 4

waitMethod · 0.80
notify_oneMethod · 0.80
lockMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected