Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <mutex>
- #include <condition_variable>
- template <class T>
- class Exchanger {
- private:
- T val;
- std::condition_variable cv;
- std::mutex m;
- public:
- Exchanger() {
- }
- T exchange(T t) {
- std::unique_lock<std::mutex> ul(m);
- val = t;
- cv.notify_one();
- cv.wait(ul);
- return val;
- }
- ~Exchanger() {
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment