C++ (Qt)void lock() { int key = 0; do { key = ++m_key; if (key > 0) m_key--; } while (key != 0); } void unlock() { m_key = -1; }