GithubHelp home page GithubHelp logo

herbertkoelman / cpp-pthread Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 6.0 1.68 MB

C++ wrapper of the pthread library

Home Page: https://redmine.urbix-software.fr/projects/urbix-cpp-pthread

License: GNU General Public License v3.0

C++ 87.74% CMake 9.88% Shell 0.51% Python 1.87%
thread pthread aix cpp

cpp-pthread's Introduction

What it does

Build Status Quality Gate Status codecov

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.

WARN 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:

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:

cmake -DCMAKE_INSTALL_PREFIX=/your/destination/

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 package will produce au tar.gz that can be distributed.

How to use it

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 with pthread ( 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.

If you use CMake, the test are built and run like this (in your build directory):

make all test

Coverage

The cmake/CoverageConfig.cmake package create a make target coverage. When used, it will produce a coverage report using lcov.

$ make coverage
[100%] Coverage report (/shared/home/herbert/c++/cpp-pthread/cmake/LCOV)
Handling directory [./CMakeFiles/cpp-pthread-static.dir/src]
Initializing [coverage.info] file
Handling directory [./googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/src]
Adding tracefile [/tmp/tmp.GQvVYkluCo.coverage] to [coverage.info]
Handling directory [./googletest-build/googlemock/gtest/CMakeFiles/gtest_main.dir/src]
Adding tracefile [/tmp/tmp.4xDeqRUZJO.coverage] to [coverage.info]
Handling directory [./tests/CMakeFiles/abstract_thread_tests.dir]
Adding tracefile [/tmp/tmp.UqJ7PH9H1e.coverage] to [coverage.info]
Handling directory [./tests/CMakeFiles/concurrency_tests.dir]
Adding tracefile [/tmp/tmp.a24dLMFBkh.coverage] to [coverage.info]
Handling directory [./tests/CMakeFiles/exception_tests.dir]
Adding tracefile [/tmp/tmp.GsxpxMbh9W.coverage] to [coverage.info]
Handling directory [./tests/CMakeFiles/synchronized_queue_tests.dir]
Adding tracefile [/tmp/tmp.NxAsqKaPSp.coverage] to [coverage.info]
Handling directory [./tests/CMakeFiles/thread_tests.dir]
Adding tracefile [/tmp/tmp.8J60C5yNeg.coverage] to [coverage.info]
Reading tracefile coverage.info
                                          |Lines       |Functions  |Branches
Filename                                  |Rate     Num|Rate    Num|Rate     Num
================================================================================
[/shared/home/herbert/c++/cpp-pthread/]
include/pthread/condition_variable.hpp    |64.7%     68| 100%     5|    -      0
include/pthread/lock_guard.hpp            | 100%     28| 100%     6|    -      0
include/pthread/sync_queue.hpp            |79.3%     29|77.8%     9|    -      0
include/pthread/thread.hpp                |83.3%     12|83.3%     6|    -      0
src/condition_variable.cpp                |68.8%     64|80.0%    10|    -      0
src/exceptions.cpp                        |91.5%     47|88.2%    17|    -      0
src/mutex.cpp                             |81.8%     33|83.3%     6|    -      0
src/pthread.cpp                           | 100%      2| 100%     1|    -      0
src/read_write_lock.cpp                   |69.6%     46|72.7%    11|    -      0
src/thread.cpp                            |79.0%    162|92.6%    27|    -      0
tests/abstract_thread_tests.cpp           |98.0%     99| 100%    13|    -      0
tests/concurrency_tests.cpp               |93.5%    123| 100%    12|    -      0
tests/exceptions_tests.cpp                |97.8%    181|95.2%    21|    -      0
tests/synchronized_queue_tests.cpp        |94.5%    109|94.4%    18|    -      0
tests/thread_tests.cpp                    |88.1%    201|95.2%    21|    -      0
================================================================================
                                    Total:|87.2%   1204|91.3%   183|    -      0

WARN you have to run the test before a report can be displayed (make all test).

Usefull links

Memory management on AIX

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).

project links

other things

Conan

This project can produce Conan Artefacts using these commands:

$ conan create .. rcs/testing
...
$ conan upload cpp-pthread
...

misc

Diagrams

overview

cpp-pthread's People

Contributors

herbertkoelman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cpp-pthread's Issues

Use auto_ptr when compiling with pre C++11 compilers

This should avoid this message:

thread.cpp:126:12: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
       std::auto_ptr<pthread::abstract_thread> pat(_threads.front());
            ^
In file included from /usr/include/c++/5.3.1/memory:81:0,
                 from ../include/pthread/thread.hpp:15,
                 from thread.cpp:9:
/usr/include/c++/5.3.1/bits/unique_ptr.h:49:28: note: declared here
   template<typename> class auto_ptr;

Doesn't compile on Fedora 23/gcc 5.3.1

Funny how compilers behave differently !!??

$ make
g++  -x c++ -std=c++11 -frtti    -I ../include -I ./ -c exceptions.cpp
exceptions.cpp:29:56: erreur : virt-specifiers in ‘what’ not allowed outside a class definition
   const char *pthread_exception::what() const noexcept override{
                                                        ^
Makefile:65: recipe for target 'exceptions.o' failed
make: *** [exceptions.o] Error 1

Fix performance related issue

include/pthread/exceptions.hpp:39,performance,passedByValue:
Function parameter 'message' should be passed by reference.

include/pthread/exceptions.hpp:71,performance,passedByValue:
Function parameter 'message' should be passed by reference.

include/pthread/mutex.hpp:83,performance,passedByValue:
Function parameter 'message' should be passed by reference.

include/pthread/exceptions.hpp:71,performance,passedByValue:
Function parameter 'message' should be passed by reference.

thread.cpp:75:23: erreur : ‘PTHREAD_STACK_MIN’ was not declared in this scope

g++ -I ../include -I ./ -x c++ -std=c++11 -frtti -g -O2 -c thread.cpp
thread.cpp: Dans le constructeur ‘pthread::thread::thread(const pthread::runnable&, std::size_t)’:
thread.cpp:75:23: erreur : ‘PTHREAD_STACK_MIN’ was not declared in this scope
if ( stack_size > PTHREAD_STACK_MIN && (rc = pthread_attr_setstacksize(&attr, stack_size)) != 0 ){
^
Makefile:64: recipe for target 'thread.o' failed

Pre-release v1.3.2 is not running on Mac OS X

iMac-de-herbert:tests herbert$ ./without-cpp11-pthread-tests 5
lib version: cpp-pthread v1.3.1 - bc377cb2421f92243f452c150d5171270020a182 - compiled on Darwin Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64.
add new work to thread group
add new work to thread group
add new work to thread group
add new work to thread group
add new work to thread group
Segmentation fault: 11

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.