Thread waiting

Hello!

I have som problems with the thread drawing the
different Surfaces. Unfortunately I have realized that
one single thread handeling all the Surfaces is the
only way of doing this.
Now the problem is how to give this thread the
different Surfaces. My idea is to “post” them to the
thread. And a while loop blits the Surfaces. Now this
while loop has to sleep until there is a new Surface
to be blited in the que.
How do I tell this thread to wait until this Surface
buffer isn’t empty. Something like SDL_WaitEvent…

Thanks for all help!!
/Martin

H?strusk och gr? moln - k?p en resa till solen p? Yahoo! Resor p? adressen http://se.docs.yahoo.com/travel/index.html

At 11:57 AM 01/10/2003 +0200, you wrote:

Hello!

I have som problems with the thread drawing the
different Surfaces. Unfortunately I have realized that
one single thread handeling all the Surfaces is the
only way of doing this.
Now the problem is how to give this thread the
different Surfaces. My idea is to “post” them to the
thread. And a while loop blits the Surfaces. Now this
while loop has to sleep until there is a new Surface
to be blited in the que.
How do I tell this thread to wait until this Surface
buffer isn’t empty. Something like SDL_WaitEvent…

I’d imagine this could be achieved with a semaphore controlled wait queue.

There’s probably a neater way but have two semaphores (mutexes
really), one for access to the queue to prevent race hazards, and the
other set (1) when there is something in the queue and not set (0) when
there is nothing, then the blitting thread can wait on this second
semaphore until the buffer isnt empty. Get the threads posting the
surfaces to release the second semaphore if they change the amount in the
buffer from empty to having something in it.

HTH,

Neil.