Multithreading and Cancellation #32
Unanswered
gregjohnson2017
asked this question in
Q&A
Replies: 1 comment
-
The channel blocks and waits for data to be written. It's by design. What you can do is close the channel. Then you cannot write to it any more and it will unblock. Though the The multithreading example never terminates because that's the use case it presents: a long-running program that continuously passes data into the channel and reads it from. Indeed, the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use the channels that this project offers to communicate between threads in a project that I'm working on. However, I'm wondering how to use the std::stop_token cancellation feature of thread/jthread when my runner thread is blocked trying to read from a channel.
I ran
examples/multithreading.cpp
to see an example of threads using channels to communicate and then being gracefully terminated, but unfortunately this example appears to never terminate. The example code calls join on every reader and the writer, however the main thread will just block on the first join call, since none of the writers/readers are ever cancelled. As a side note, I believe there is also a race condition in how std::cout is being written to concurrentlyBeta Was this translation helpful? Give feedback.
All reactions