...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <condition_variable> #include <mutex> struct node_tNode { void *node; struct node_tNode *next; }; static node_tNode list; static std::mutex m; static std::condition_variable condition; void consume_list_element(std::condition_variable &condition) { std::unique_lock<std::mutex> lk(m); if (list.next) { condition.wait(lk); } // Proceed when condition holds. } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <condition_variable> #include <mutex> struct node_tNode { void *node; struct node_tNode *next; }; static node_tNode list; static std::mutex m; static std::condition_variable condition; void consume_list_element() { std::unique_lock<std::mutex> lk(m); while (list.next) { condition.wait(lk); } // Proceed when condition holds. } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <condition_variable> #include <mutex> struct node_tNode { void *node; struct node_tNode *next; }; static node_tNode list; static std::mutex m; static std::condition_variable condition; void consume_list_element() { std::unique_lock<std::mutex> lk(m); condition.wait(lk, []{ return !list.next; }); // Proceed when condition holds. } |
...