Threads and C++14

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Threads and C++14

      I am trying to learn as much C++11/14 in this game project as I can. I've seen a lot of std::thread floating around on the internet. It looks like Game Coding Complete seems to use an alternative CreateThread() API.

      Any comments on what the differences/advantages to each approach are?
    • CreateThread is Windows specific while std::thread should work with all C++11 compilers / platforms.

      I am writing a small 2D Engine based on some GCC4 concepts but with OS X as a target platform so I rewrote the multithreading part of GCC4 using C++11 features...
    • Hey, I use std::thread personally an I can say it is very very good, it is essentially the boost::thread library as it is modelled after it as well as written by the guy who did the boost::thread library.

      It ties in very nicely with other STL classes and C++11 such as lambdas & std::function, and if you ever need to do anything that isn't supported, for example, naming threads in the Visual Studio debugger, you can simply grab the native thread handle from the std::thread and manipulate it from there.

      I recommend the book 'C++ Concurrency in Action - Practical Multithreading', the lead brain behind boost/STL thread wrote it, and I can say personally it is an AWESOME book. Especially take a look at the section on worker thread pools for some crazy C++11 voodoo.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Awesome, I'll check that book out.

      I've been using MPI for distributed parallel computing at my place of employment. Do you guys know of any similarities/differences that I should keep in mind? I realize it's a shot in the dark to ask since MPI is a bit more obscure - thought I might as well ask though.
    • C++11 is relevant to mobile development, so long as your targeted device range can support it, at work we can support a minimal sub-set of C++11 for the IPhone target, I think this would depend also on the graphical capabilities of the game, for instance if you are doing a full 3D game on Android/IOS you can guarantee you won't be making Android "Froyo" a target device, it's just too old and the devices are too low on capabilities, this may open the door to more C++11 capabilities. If we were to raise our device requirements just 1 level, we would be able to utilize the C++11 compatible LLVM compiler.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Most of the people I know (including me!) are doing cross platform mobile development using Unity and scripting in C#, so really I think we're already there in terms of platform capability. It turns out that speed and ease of development has always (well mostly always) trumped raw speed in terms of the language choice used in the bulk of development for almost anything.
      Mr.Mike
      Author, Programmer, Brewer, Patriot

    • I am trying to learn as much C++11/14 in this game project as I can. I've seen a lot of std::thread floating around on the internet. It looks like Game Coding Complete seems to use an alternative CreateThread() API.

      Any comments on what the differences/advantages to each approach are?

      I honestly don't know what the differences are from a performance or stability point of view, but I imagine it's going to be better than CreateThread(). We used CreateThread() because C++ 11 had JUST come out and Visual Studio 2010's support of C++ 11 was shaky at best. 2013 is much better. If we were to write that chapter today, we almost certainly would have used the new C++ 11 threading API.


      Maybe not the question for this topic, but.. Are new standards of C++ are applicable to current game development? I mean stuff like native mobile and console development, also it's very interesting to me whether UDK 4 will support at least C++11 when it come out...

      Yes and no. At Maxis, the only official C++ 11 stuff we're allowed to use is the auto keyword. This is because many compiles and platforms (mac) haven't caught up with C++ 11. Even though we're doing PC development right now, we don't want to create a headache for ourselves should we decide to pursue another sku. We adopt the changes at the rate of the slowest adopter.


      Most of the people I know (including me!) are doing cross platform mobile development using Unity and scripting in C#, so really I think we're already there in terms of platform capability. It turns out that speed and ease of development has always (well mostly always) trumped raw speed in terms of the language choice used in the bulk of development for almost anything.

      Unity is great! It's the perfect tool for small - medium games, which define mobile games and many indie games quite nicely. It breaks down on very large projects so I wouldn't use it for something like The Sims or Mass Effect. Those games are big enough that they really do need the speed granted by C++ (a common optimization is to push code into C++ for massive performance gains). That's where I think it's really relevant and will stay relevant.

      That having been said, I would have killed for something like Unity back when I was working on RatRace or Drawn to Life....

      -Rez