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

前端 未结 12 985
小鲜肉
小鲜肉 2020-12-14 01:36

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

相关标签:
12条回答
  • 2020-12-14 01:54

    Pthreads are running only on POSIX systems. QThread from Qt is a way to go. It is available on platforms: Linux, Mac OS X, Windows, Embedded Linux, Windows CE, Symbian, Maemo.

    0 讨论(0)
  • 2020-12-14 01:55

    I have used pthreads for code that work on multiple platforms. To get around the Windows lack of pthreads, I have used the following open source library with great success: POSIX Threads for Windows

    0 讨论(0)
  • 2020-12-14 01:57

    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
    0 讨论(0)
  • 2020-12-14 01:58

    There is a threading library coming with C++11. It's built upon the boost threading library. Unfortunately, I seem to remember that there are non-trivial differences between Boost.Threads and what C++11 comes with. Still, if you plan to switch to the C++ standard threading library, I believe Boost.Threads is the closest you can get to now.

    I suppose that, under the hood, these libraries will use Pthreads on POSIX systems and whatever native threading support is available elsewhere.

    Disclaimer: I haven't worked with either of the two.

    0 讨论(0)
  • 2020-12-14 01:58

    Qt has pretty good thread support. If you just need to create a thread and run some code in it, QThread is all you need. There are many other high-level classes that can help you with thread pools or even abstract the concurrent execution (the QtConcurrent framework).

    0 讨论(0)
  • 2020-12-14 02:01

    List the concerning platforms. If you're only using say, Linux/Mac/Windows, then boost::thread will likely do you fine until C++0x (harhar) provides std::thread.

    0 讨论(0)
提交回复
热议问题