Sign in to follow this  
sander242

Multithreading SDL

Recommended Posts

Is multithreading with SDL useful, when you don't have a multicore CPU, and is it even possible? :D Because i want to write a piece of code that could constantly update a picture and in the same time i want the program to be able to receive input from the user at any given time. I thought it's only possible by multithreading, is it?

Share this post


Link to post
Share on other sites
Multithreading is possible even on a single-core CPU but only on a multi-core two threads can run really simultaneously (concurrent). On a single-core CPU the concurrency is only emulated by giving each thread a short time slice on the CPU (but is does that *really* fast so you dont feel it).

Have a look at: http://en.wikipedia.org/wiki/Multithreading for details.

Threading is useful when you have a part of you program that has to wait for a certain event but you want to continue your flow. But it makes debugging a lot harder because, so only do it if you really want to get into trouble (or know how to deal with it).

For your case it is probably not necessary. In SDL you usually query the SDL event system each frame for input events that you process. If your drawing is reasonably fast (e.g. > 20 fps) this should suffice for manipulating the image and give an impression of manipulating the image directly.

Share this post


Link to post
Share on other sites
If it's for gameprogramming with SDL, just do a single thread with an update loop. Then you first check input, then draw to the screen. Computers are that fast :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this