ofThreadで作成したスレッドの実行速度は不定
ofThreadで作成したスレッドの実行速度は不定で、ofSetFrameRate()
でも制御できない。
ofTimer
を使う
forum.openframeworks.ccでofTimerを利用した方法があった。
60fps(16ms)。で動かしたい場合は、以下のようにする。
class ThreadedUpdate : public ofThread {
public:
void setup() {
timer_.setPeriodicEvent(16666666); //引数の単位は、ns
startThread();
}
void draw() const {
}
private:
void threadedFunction() {
while(isThreadRunning()) {
timer_.waitNext();
if(lock()) {
//...do something
unlock();
} else {
ofLogWarning("threadedFunction()") << "Unable to lock mutex.";
}
}
}
ofTimer timer_;
};