theSum.red += сolor.red;
C++ (Qt)struct ARGB { QMutex mutex; float alpha, red, green, blue;}; ARGB theSum; // глобальная переменная.... void ThreadFunc( void * ) // рабочая ф-ция нитки{ ... ARGB color; EvalColor(&color); ... theSum.mutex.lock(); theSum.red += color.red; theSum.mutex.unlock(); ...}
C++ (Qt)...
C++ (Qt)struct ARGB { float alpha, red, green, blue; inline void lock (void) {while (!mutex.testAndSetAcquire(0, 1));} inline void unlock (void) {mutex.testAndSetRelease(1, 0);)private: QAtomicInt mutex;}; ARGB theSum; .... void ThreadFunc( void * ) { ... ARGB color; EvalColor(&color); ... theSum.lock(); theSum.red += color.red; theSum.unlock(); ...}
C++ (Qt)struct ARGB { float alpha, red, green, blue; }; struct SimpleLocker { inline void lock (void) {while (!mutex.testAndSetAcquire(0, 1));} inline void unlock (void) {mutex.testAndSetRelease(1, 0);)private: QAtomicInt mutex;}; ARGB theSum; SimpleLocker SumMutex;.... void ThreadFunc( void * ) { ... ARGB color; EvalColor(&color); ... SumMutex.lock(); theSum.red += color.red; SumMutex.unlock(); ...}
C++ (Qt)while (!mutex.testAndSetAcquire(0, 1));