Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PThread vs boost::thread?

Tags:

Having no experience with threading in the past, which threading technique in C++ will be the easiest for a beginner? boost::thread or pthreads?

like image 922
Chris Avatar asked Jan 31 '10 01:01

Chris


People also ask

Does boost use pthread?

Since boost is mainly just a wrapper around pthreads (on posix platforms) it helps to know what is going on underneath. In attempting to be generic, boost leaves the platform specific functionality unwrapped. In order to get to it you need to use the native_handle() calls.

Does std :: thread use pthread?

The std::thread library is implemented on top of pthreads in an environment supporting pthreads (for example: libstdc++).

Is OpenMP faster than pthreads?

The results shows that OpenMP does perform better than Pthreads in Matrix Multiplication and Mandelbrot set calculation but not on Quick Sort because OpenMP has problem with recursion and Pthreads does not.

Is pthread still used?

Yes, the pthreads library is still used for threading. There are some higher level libraries (boost, or if you have a c++ 11 compliant compiler, the standard library) that will also give you threading capabilities, although for somethings you will still need to fall back to the plain pthread call.


2 Answers

I'll go in the opposite direction of everyone else - learn (or at least familiarize yourself with what is available in) pthreads.

Since boost is mainly just a wrapper around pthreads (on posix platforms) it helps to know what is going on underneath. In attempting to be generic, boost leaves the platform specific functionality unwrapped. In order to get to it you need to use the native_handle() calls. In order to use the native_handle() calls you need to know what the platform offers.

Think of it like sockets. There are dozens of socket classes and frameworks. But ultimately they wrap the underlying platform's socket API. Your understanding is always richer by knowing it - and knowing in what ways your class abstractions might have short comings.

like image 133
Duck Avatar answered Sep 19 '22 08:09

Duck


Go for boost::thread. It's closely related to the work on the upcoming C++ standard threads, and the interface is quite easy to use and idiomatic to C++ (RAII instead of manual resource management).

like image 40
Malte Clasen Avatar answered Sep 21 '22 08:09

Malte Clasen