Some C/C++ compilers are not implementing all of C++11 and above standard, it's often lacking the concurrency features that the standard brings. These compilers will at some point be updated. I was therefore looking for a way to reduce the effort of switching from a specific implementation to the C++11 standard one.
This projetc is the resulting code.
Of course, this library is a replacement of C++11 features, it is best to use the standard implementation if your compiler support it.
To use this library:
configure
make
make install
or
mkdir build && cd build
cmake ..
make install
Install moves files into your system's default location for headers and libraries (often /usr/local/include and /usr/local/lib). Use this command line argument to change install target directory:
configure --prefix=/usr/local
Doxygen documentation can be generated with this command. I hope this help make things easier to use and understand.
make doxygen
Doxygen can be downloaded here.
The make
target pkg
will produce au tar.gz that can be distributed.
Once compiled and installed in a location that suites you, use your compiler options to reference the headers and the library directory. In almoast all casses you can:
- include
#include "pthread/phtread.hpp"
in your code to replace of the standard includes. - replace
std
namespace withpthread
( std::condition_variable becomes pthread::condition_variable, etc)
Once your compiler is upgraded you simply include the standard #include <thread>
and replace the namespace pthread
for std
.
Sample code can be found in the tests
directory. To use it, run the following commands:
cd tests ./configure ./make
WARNING tests rely on GoogleTest and which MUST be installed before building.
If you use CMake, the test are built and run like this (in your build
directory):
make all test
Memory management on AIX is quite sophisticated, memory managementcan be fine tuned very precisely. Consider using these compiler/linker options when using pthreads:
- -bmaxdata:0xN0000000 this option activates the large memory model, N is a number in the range of [1-8].
- -bmaxmem=-1 this option tells the compiler to use as much memory it needs to optimize your code.
Thread stack size:
- 32bits programs allocate 96KB per thread on the program's heap.
- 64bits programs allocate 192KB per thread on the program's heap.
On many Linux implementations and on Mac OS X the stack size is defaulted to 8MB. You may consider setting this as a default.
More detailed information can be found in this RedBook (chapter 8).
- POSIX Threads documentation
- std::thread implementation we try to mimic
- std::lock_guard implementation we try to mimic
- std::mutex implementation we try to mimic
- std::condition_variable implementation we try to mimic
This project can produce Conan Artefacts using these commands:
$ conan create .. rcs/testing
...
$ conan upload cpp-pthread
...
- author herbert koelman (herbert.koelman@me.com)
- github cpp-pthread