Reputation: 73
I'm developing an application in C++11 which uses SDL as a library. I'm planning to add multithreaded support for my app. Is there any difference whether to use SDL_Thread or std::thread in my application?
Upvotes: 3
Views: 2244
Reputation: 593
Unless you're using a part of the SDL API that specifically requires SDL's thread handle type, you're better off using C++'s std::thread
. The API is more idiomatic (e.g. the constructor allowing you to forward arguments to start function) and does not tie that code to what SDL provides.
The reason I mention the handle is if you actually need to pass an SDL_Thread *
, there is no way to query for handle to the current thread. Granted std::thread
does not provide this either, but since the interface is richer, it makes more sense to use.
Edit: Both interfaces seem to draw heavily from POSIX threads, but with one exception. std::thread
does not have a built-in cancellation function. Normally, you don't want to kill a thread anyway without any sort of cleanup, but it is worth mentioning.
Upvotes: 4