@TimChi wrote:
Hi,
I’m working thru the threadExample; its my first time with ofThread.I noticed that all of the local variables in threadedFunction() are auto, and that atomic is included in the header file threadedObject.h. So, I’m thinking that the compiler will construct atomic versions of variables when auto is used. Does anyone know if this is correct? And if so, are atomic variables required, or good practice? Thanks for the help! The code from threadedObject.h is below, minus the comments:
void threadedFunction(){ while(isThreadRunning()){ threadFrameNum++; std::unique_lock<std::mutex> lock(mutex); auto t = ofGetElapsedTimef(); for(auto line: pixels.getLines()){ auto x = 0; for(auto pixel: line.getPixels()){ auto ux = x/float(pixels.getWidth()); auto uy = line.getLineNum()/float(pixels.getHeight()); pixel[0] = ofNoise(ux, uy, t); x++; } } condition.wait(lock); } }
Posts: 4
Participants: 2