PDA

View Full Version : multithread; how to tell opengl-thread to redraw



ludo.pagie
09-26-2003, 03:48 AM
Hi,

I'm fairly new at opengl and multithreading. That said I have the following problem:

I'm writing a numerical-analysis program which does a lot of computation. Therefor I want to use two threads, an opengl thread and a numerical thread.

How can I sensibly notify the GL-thread that computations have led to new data to be drawn. I can't use something like glutPostRedisplay() directly; the GL-thread doesn't react to that. I don't want the GL-thread to constantly check for a condition-flag in its idle function, thereby consuming lots of CPU-time.

Is the only sensible way to for GL's idle-func to check for a condition-flag and sleep for some micro-seconds if condition is not met (which is the best suggestion I've found sofar)????

Thanks, Ludo

marcus256
09-26-2003, 02:08 PM
That depends on what threading environemnt you are using. If you use POSIX threads (or similar), then condition variables are exactly what you are looking for (in combination with a mutex). You can let a thread wait for the condition variable (read: sleep), and another thread signal the condition variable to wake up the waiting thread(s). Then have a flag/counter to indicate if new rendering is needed, and protect this flag with a mutex or critical section so that both threads can safely access it.

If you do not have condition variables, you should be able to do something similar with signals or events.