[SDL] (openGL repaint) thread problem

David Olofson david.olofson at reologica.se
Fri Aug 10 09:16:01 PDT 2001

On Friday 10 August 2001 15:20, Johann Deneux wrote:
> I don't really see why you want to use a thread to paint. As soon
> as another threads tries to read events, your application may crash. My
> advice is: avoid threads in this kind of situation.

I can see a few reasons to use *more* than one thread to render. Although 
there are other ways to deal with it, it may simplify things a lot if 
multiple threads can render at the same time. (Usually in different areas 
of the screen - it wouldn't work very well any other way...)

What to do? Well, you could use some kind of wrapper API for the 
rendering functions, designed with asynchronous execution in mind. Then 
implement that wrapper API on top of some thread safe queue mechanism 
(one lock-free FIFO per client thread, perhaps), so that the API calls 
enqueue "commands" instead of calling the "real" API. Finally, implement 
a "server" that takes commands from the queue (possibly with some 
priority system, and perhaps even splitting/interleaving of large 
operations) and performs them using the underlying "real" API.

(BTW, I was working on a proof-of-concept hack for SDL that could 
*really* use something like this... However, don't count on me getting 
around to code it anytime soon. *heh*)

//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`--------------------------------------> david at linuxdj.com -'

More information about the SDL mailing list