2

On Windows in Visual Studio 2013, I'm thinking C++11 threads via are better than threads because the code is then platform-independent (with compiler supporting C++11).

Could not find anyone discussing the differences between the two.

Wondering if there's any advantage to using afxwin.h, or if it's really just there for backwards compatibility now.

Not familiar with Windows programming, so concerned there may be some reason to stick with afxwin.h...

jester
  • 31
  • 3
  • Fyi, `afxwin.h` is part of MFC, which has their own wrappers around native threads. If you have a choice of which wrapper library to use, unless you are writing MFC apps (you couldn't pay me to do it) there is little reason to avoid taking the plunge and going with C++11 threading instead. Adding fuel to that fire, MFC is *not* part of the community (free) edition of VS2013, so if that is a sticking point (I believe Pro is the minimum MFC-supplied VS), you may want to consider that as well. – WhozCraig Mar 29 '15 at 03:46
  • @WhozCraig according to this post, VS2013 Community Edition does support MFC, https://stackoverflow.com/questions/30699577/is-mfc-supported-in-the-community-version-of-visual-studio and I know that it is supported in Visual Studio 2017 though it is not a default as part of the installation. – Richard Chambers Jun 02 '18 at 20:53

1 Answers1

4

C++11 threads are substantially easier to use, so they're probably preferable when possible.

Using Win32 threads directly gives you some capabilities that C++11 threads just don't provide, such as pausing threads, adjusting thread priorities, etc.

Note that you can combine the two--you can create a thread using the C++11 functions, then use the native_handle member function to obtain a Win32 handle to the thread so you can manipulate it in ways the C++11 library doesn't support directly. This probably won't be necessary very often though.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • I am curious about using C++11 threads with windows and COM objects. Since COM depends on apartments, it would seem that there might be some problems with thread context? Are C++11 threads more appropriate for worker type threads which are not depending on a particular apartment environment? – Richard Chambers Jun 02 '18 at 20:57