C++ (Qt)if (id == mTreadID)
ptr = std::make_shared<Data>();data_ready = true;/// и в другом тредеif (data_ready) foo(ptr.get());
// 0. делаем что-то нерелевантное// 1. acquire resource (testAndSetAcquire и друзья)// 2. что-то делаем с ресурсом:m_data = 1;// 3. что-то делаем с ресурсом:m_data = 0;// 4. release resource
a = 10;ready = true;
ready = true;a = 10;
C++ (Qt)template <class T>class CWeakPointer : public QWeakPointer<T> {public: CWeakPointer( const QSharedPointer<T> & other ) : QWeakPointer<T>(other) {} bool operator == ( const CWeakPointer & other ) const { QSharedPointer<T> other2 = other.toStrongRef(); // must lock hash value with multi-threading if (other2.isNull()) return false; return *(this->data()) == *(other2.data()); }}; template <class T>uint qHash( const T & val ); template <class T>uint qHash( const CWeakPointer<T> & ptr ){ const T & val = *ptr.data(); return qHash(val);}