Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux threads for dummies. Can some one explain the difference between multi-thread libraries in linux?

New to linux and c++. I wante to create an application that only needs to run on linux (ubuntuz) and i need to use basic read-write locks.

I saw that there are a few libraries that give "concurrency capabilities". e.g. to use mutexes, there are at least 3 options:

  1. pthread_mutex_lock (pthread.h)

  2. boost::mutex

  3. std::mutex (mutex)

could someone explain the differences between the various approaches?

like image 743
Avihai Marchiano Avatar asked Apr 07 '26 16:04

Avihai Marchiano


1 Answers

  • pthreads is a C-API and is available on all posix conformant systems (pthreads stands for Posix THREADS).

  • boost::mutex is a C++-only API that depends on the "boost"-library (you cannot use it in C-code; you add a dependency on "boost")

  • lots of features from boost will eventually end up in the C++ standard library, e.g. threading; with C++11 you have std::mutex, but you will need a compiler recent enough to support that recent addition. e.g. if you want your application to be backportable to older distributions you might want to avoid it.

like image 118
umläute Avatar answered Apr 09 '26 05:04

umläute



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!