#include <QMutex> //临界资源 class Key { public: Key() { key = 0; } int createKey() { QMutexLocker locker(&mutex); ++key; return key; } int value() { QMutexLocker locker(&mutex); return key; } private: int key; QMutex mutex; }
说明:
#include <QMutex> //临界资源 class Key { public: Key() { key = 0; } int createKey() { QMutexLocker locker(&mutex); ++key; return key; } int value() { QMutexLocker locker(&mutex); return key; } private: int key; QMutex mutex; }
说明: