2

In my understanding, if you use C, then you are bound to use POSIX Threads.

These are OS dependent, and if you use Linux, you have to use <pthread.h>, while if you use Windows, you have to go with <windows.h>.

These things are transferable to C++ as well.

However, if you use C++ and specifically a version after C++11, then you can skip the POSIX threads method, and use #include <thread> and you are off to go.

Is this a correct understanding? Is there something i miss?

user1584421
  • 3,499
  • 11
  • 46
  • 86
  • 2
    That about sums it up. There are (were) pthread API libraries for windows too (that just wrap, where possible, native Windows threading), but with the advent of C++11 and `` sanity suggests you use that instead. (and my goodness, was there ever much rejoicing when that came down). – WhozCraig Feb 27 '22 at 14:49
  • 1
    MinGW (at least the one from MSYS2) still bases their `` support on a Windows port of pthread, I believe. – HolyBlackCat Feb 27 '22 at 15:28

1 Answers1

5

Since C11, there is a support of threads directly in the standard C language (using threads.h). Note that mainstream compilers (Clang, GCC, ICC, MSVC) support OpenMP which can be used to parallelize computing codes using multiple threads (typically numerical codes). OpenMP is available in both C and C++ (as well as FORTRAN). Note also that PThreads is supported on Windows as a wrapping library. In pre-C++11, note that there is many portable threading libraries. One famous library is the Intel Threading Building Blocks (aka TBB).

Related question: Multi-Threading support in c11

Jérôme Richard
  • 41,678
  • 6
  • 29
  • 59