class Test { public: Test(); static std::condition_variable condVar; void notifyCv(); // тут делаем condVar.notify_all() }
when trying to use such a variable, it returns undefined reference.
void main() { std::mutex mut; std::unique_lock<std::mutex> lock(mut); while (true) { Test::condVar.wait(lock); //далаем чтото полезное } }
The fact is that many instances of the Test class are created, and in these instances an event occurs that must be constantly waited. And you need to respond if an event occurred in any instance.
If you declare condVar, not as static, then each instance will have its own condVar and how then to expect an event from any of the instances without iterating over them all the time in a loop?
upd: yes, the question is similar to a duplicate .. that the static variable needs to be determined - I know. But I do not understand how to do this with condition_variable ..
std::condition_variable Test::condVar;
- KoVadim