#include #include std::queue q; // Queue which multiple threads might add/remove from std::mutex m; // Mutex to protect this queue void AddToQueue(int i) { std::lock_guard lg(m); // Lock will be held from here to end of function q.push(i); } int RemoveFromQueue() { int i = -1; { std::lock_guard lg(m); // Lock held from here to end of scope if (!q.empty()) { i = q.front(); q.pop(); } } return i; }