Possible Duplicate:
PThread vs boost::thread?
I have been using pthreads library programming examples since the time I understood what is multithreading. Of late I came across the Boost thread library on the internet and got curious. Can anyone specify what are the prominent differences between the two? Are there any extra privileges suppiled from Boost, If yes then what are those?
The design of boost::thread was strongly influenced by pthreads, but of course styled as a C++ library instead of a C library. Here are few differences that come to my mind. I do not claim this to be an exhaustive list of differences.
Things pthreads has that boost::thread lacks:
When you use boost::thread you can grab the underlying
pthread_t
(orpthread_mutex_t
, etc.) by calling thenative_handle()
member function, and use it to regain back functionality not supplied directly by boost::thread.
pthread_attr_setschedparam
)pthread_attr_getstacksize
)pthread_mutex_getprioceiling
)Things boost::thread has that pthreads lacks:
The following things can be done in pthreads (after all boost::thread is implemented on pthreads). But there isn't clear and direct API in pthreads to do these things.
In my experience the boost::thread library has functionality that very closely ties to pthreads. There are some things provided in pthreads that are external to the boost::thread library, but still available in boost (such as semaphores as provided in boost::interprocess).
The main benefits I've seen is the ability to [more] easily write cross-platform code. Since the boost::thread library appears to be implemented as a cross-platform interface layer to various operating system primitives, I don't believe there are significant additional features to be found in boost::thread that wouldn't be available in the actual operating system APIs.
In fact, there are however some underlying features of Windows that I have not been able to find a true equivalent for, mostly from my experience with Win32, and almost certainly because of my limited exposure to what is provided in both the boost::thread and pthread libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With