Home › Forums › C Programming › multithreading on OSX › Reply To: multithreading on OSX
Actually, I think I’ve actually identified the problem. I think it was the sleep() function in my thread loop. I understand why I need that if the loop is continuously running and doing heavy stuff, but do I need it in my case?
When I comment out the sleep line (As below), the behaviour looks a lot smoother and correct, maybe because as soon as I set the bHasRunThisFrame flag in the thread instance to false, the update function is called almost immediately (which is what I want), whereas with the sleep() function, maybe there was a delay of upto interval before the update kicked in?…. or something :P Is it bad to not have a sleep function in there?
// run the update function in another thread
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | void MSAThread::threadedFunction() {<br /> while(isThreadRunning()) {<br /> if( lock() ){<br /> if(bAutoLoop || !bHasRunThisFrame) {<br /> update();<br /> bHasRunThisFrame = true;<br /> unlock();<br /> // ofSleepMillis(interval);<br /> } else {<br /> unlock();<br /> }<br /> }<br /> }<br /> }<br /> |