Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any cross-platform threading library in C++?

I'm looking for some easy to use cross-platform threading library written in C++.

What's your opinion on boost::thread or Pthreads? Does Pthreads run only on POSIX compliant systems?

What about the threading support in the Qt library?

like image 629
NumberFour Avatar asked Apr 01 '10 15:04

NumberFour


People also ask

Does C allow multi threading?

C does not contain any built-in support for multithreaded applications. Instead, it relies entirely upon the operating system to provide this feature. This tutorial assumes that you are working on Linux OS and we are going to write multi-threaded C program using POSIX.

Is Pthread cross platform?

It is cross platform between Windows and Linux.

What are the three main thread libraries in use?

Three main thread libraries are in use today: POSIX Pthreads, Win32, and. Java.


1 Answers

Boost.Thread is the draft for the coming standard threading library of the C++ language. Knowing that, I prefer to use it as it provide some strong guarantees (because it becomes standard).

Update: Now that we have the standard threading libraries, some more precisions. Some boost constructs, like boost::shared_mutex, have not been standardised (but might be later). However the standard library exploit the move semantic better. Good to know before choosing a library. Also, using C++11 threading library requires a compiler that provides it. It's not the case for all compilers today.

Update: Now [Nov2012] most of the Standard compilers provide C++11 threading library. VS2012, GCC4.8 and Clang3.1 have support for threads and synchronization primitives and atomic operations. For complete implementation you can also use just thread by Anthony Williams. It is C++11 compliant library supported on Windows/Mac and Linux.

Links for status of C++11 features with various compilers:

  • GCC 4.8 - http://gcc.gnu.org/gcc-4.8/cxx0x_status.html
  • Clang3.1 - http://clang.llvm.org/cxx_status.html
  • VS2012 - http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
like image 171
Klaim Avatar answered Oct 08 '22 20:10

Klaim