3 ms·
Multithreaded programming in C++11 is pretty convenient. std::thread, together with std::chrono are very good threading and timing libraries. The only thing bet
by exDM69 15y ago
Multithreaded programming in C++11 is pretty convenient. std::thread, together with std::chrono are very good threading and timing libraries. The only thing better than that is using native API's like pthreads + posix clocks.
Here's an example: C++11 has timed wait on mutex and condition variables, using std::chrono time stamps for absolute and relative times. Most threading wrappers don't provide this but it's available in pthreads (and I guess Windows API too). Not only does C++11 provide this but it plays along very nicely with the clocks in chrono and you can use it with different time sources, like the monotonic system clock.
I've used both when building multithreaded "main loops" for game/simulation purposes. Using C++11 threads + chrono is a lot nicer to the programmer than doing the same with posix pthreads in C. The biggest improvement is exception safety, type safety and rich types for clocks and timestamps come second.
- ajross 15y agoIt's pedantry, but pthreads isn't "native" anywhere either. It's a standardized API on top of lower level primitives (in Linux, clone() and futex() basically).