herbertkoelman / cpp-pthread Goto Github PK
View Code? Open in Web Editor NEWC++ wrapper of the pthread library
Home Page: https://redmine.urbix-software.fr/projects/urbix-cpp-pthread
License: GNU General Public License v3.0
C++ wrapper of the pthread library
Home Page: https://redmine.urbix-software.fr/projects/urbix-cpp-pthread
License: GNU General Public License v3.0
Transform so that we can use it like this:
lock_guard<mutex> lck{mtx};
...
On AIX this macros is 199711L
Need debugging
It seems to run faster when destructor is not virtual !!
g++ -x c++ -std=c++11 -frtti -I ../include -I ./ -c thread.cpp
thread.cpp: Dans la fonction membre ‘void* pthread::thread::join()’:
thread.cpp:33:21: erreur : invalid operands of types ‘pthread_t {aka long unsigned int}’ and ‘std::nullptr_t’ to binary ‘operator!=’
if ( _thread != nullptr){
For now I'm passing to the running thread function a reference to a runnable object. This can be enhanced.
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
Thread number argument is at position 1 and not 0.
int number_of_threads = 2;
if ( argc > 0 ){
number_of_threads = atoi(argv[1]);
}
Therefore we must test that argc is exactly equal to 2 (argument 1 is the program name and is always there)
Add a make target that runs cppcheck on the code.
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.
Check timeval calculation algorithm.
Check if this library can be used on AIX xlC 13.1.2
Re-check
This is not supported by all compilers(grrrrr).
Error code 0 means success (kind of strange for an exception).
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
more information about doxygen here.
Method wait
and wait_for
should accept a lock_guard reference as parameter.
wait( lock_guard &lck);
wait_for(lock_guard &lck, int millis, lambda);
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;
See chapter 8 in this redbook redbook-dev-c-c++-apps-aix.pdf
For now only two methods accept a reference to a lock_guard. Extend this to all wait
and wait_for
methods in condition_variable
.
This target runs autoconf and thus updates the library's version info (using git).
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
thread& operator= (thread&& rhs) noexcept;
thread& operator= (const thread&) = delete; // copy [deleted]
Very simple synchronized fixed size queue (suitable for pre C++11 compilers)
Need to update the sample part.
Remove unnecessary checks
./include/pthread/pthread_exception.hpp:28:111: Use of undeclared identifier 'pthread_number'
[src/condition_variable.cpp:71] -> [src/condition_variable.cpp:79]: (style) Variable 'tv_nsec' is reassigned a value before the old one has been used.
Create tag v1.2.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.