|
From: Stephan A. <sup...@gm...> - 2007-08-29 14:18:32
|
Vlastimil Mil=C3=A9=C5=99 wrote (2007-08-29, 15:44:44 =5B+0200=5D): > Uhm, threads are tricky. They do not seem tricky, but they are. I have=20 > seen and worked on my share of threaded programs and there is usually no= =20 > visible speed benefit. A poorly designed application with threads can be= =20 > slower than a simple single-thread solution. >=20 > Threads will only benefit you if you: > a) expect that the time needed to render subsequent frames will be very=20 > variable That is exactly the problem which I tried to solve in my application. I=20 wanted it to survive peaks of processing times which are longer than the=20 frame duration for a short period of time. > b) or if you=27ll use more than one thread (and more than one processor) = to=20 > work on multiple frames concurrently Depending on what is happening in your rendering function, this could=20 indeed enlargen the requirements of your data structures considerably. > Otherwise, if you expect the frame rendering times to be roughly the same= =20 > and that one processor should be able to handle the animation nicely,=20 > just stick with single thread. You will save yourself a lot of useless=20 > work. Use UpdateWindow to make things a bit smoother. Well. You need to know the requirements of your application very well. You= =20 need to be quite sure that they don=27t become more complicated soon. For=20 example, let=27s add synchronous sound playback to the mix. Also in my=20 experience, the assumption that the rendering time stays mostly constant is= =20 _very_ rare in real life. If your framerate is allowed to vary with the=20 computation time, than that is fine. But the original question was how to=20 harmonize the rendering and display frame rate. And for this particular=20 problem, I have found multithreading to be an elegant solution. > And one more thing, you do not want to use realtime priority on your=20 > worker thread. Yes, that is what I tried to say. The buffer switch thread mostly sleeps,=20 but it needs to wake up at the correct point it time. :-) Best regards, -Stephan |