SDL threads vs C++11 threads

Hi everyone,

I’ve been working on my own basic SDL/OpenGL framework for a couple of years now and have decided it’s finally time to tackle the issue of multithreading. I wrote my code to break the main loop into a series of tasks which can then be run either in serial or parallel. Right now, I’m running in serial but would like to set up a thread pool to submit the tasks as they become available to be run. On a non-game code, I successfully got a thread pool up and running with C++11 std::thread and was pretty happy with it. However, my game code is highly dependent on SDL everywhere and I was wondering if there are good reasons to go with SDL threads instead? It seems that most of the functionality with SDL threads is the same as what’s available with C++11 threads (although there are some exceptions) and as far as I know both simply use pthreads behind the scenes (on Unix/Linux architectures at least; I’m developing on Ubuntu Linux btw). But maybe that’s not the case if I try to port my code to other architectures such as Windows, Android (via NDK) and iOS? If there’s anyone who has similar experience with SDL I’d be very happy to hear your advice. Thanks :slight_smile:

The biggest difference is that SDL and OpenGL are in C. If maintaining C compatibility is important or if you can’t assume C++11 compiler support, then go for SDL threads.

Otherwise, if you’re getting the results you want from std::thread, do it that way!

Also keep in mind that threading and graphics don’t always go together smoothly. (see discussions about restrictions on rendering outside the main thread)