boost mutex

boost mutex

boost mutex

better use boost::shared_mutex!!
=> see boost::shared_mutex

essentials

  • mutable
  • scoped_lock

boost::mutex example

#include "boost/thread/mutex.hpp" /* mutex* */

class Some {
#define _DOBODIESLOCK() \
    boost::mutex::scoped_lock __lk(this->bodiesLock); \
    (void)(__lk)

    Foo getFoo(void) const
    {
        _DOBODIESLOCK();
        ...
        Foo ret = this->foo:
        ...
        return ret;
    }
    void setFoo(Foo const& foo)
    {
        _DOBODIESLOCK();
        ...
        this->foo = foo;
        ...
    }

    Foo foo;
    mutable boost::mutex bodiesLock;/* !! */
#  undef _DOBODIESLOCK
};

boost shared mutex

essentials

  • mutable
  • shared_lock for read
  • upgrade_lock and upgrade_to_unique_lock for write

example

#include "boost/thread/shared_mutex.hpp" /* shared_mutex */

class Some {
#define _DOSHAREDREAD() \
    boost::shared_lock<boost::shared_mutex> __rLock(this->rwlock); \
    (void)(__rLock)
#define _DOEXCLUSIVEWRITE() \
    boost::upgrade_lock<boost::shared_mutex> __uplock(this->rwlock); \
    boost::upgrade_to_unique_lock<boost::shared_mutex> __wLock(__uplock); \
    (void)(__wLock)

    Foo getFoo(void) const
    {
        _DOSHAREDREAD();
        ...
        Foo ret = this->foo:
        ...
        return ret;
    }
    void setFoo(Foo const& foo)
    {
        _DOEXCLUSIVEWRITE();
        ...
        this->foo = foo;
        ...
    }

    Foo foo;
    mutable boost::shared_mutex rwlock;
#  undef _DOSHAREDREAD
#  undef _DOEXCLUSIVEWRITE
}:

use-eigen

use-eigen

#


eigen

eigen / eigen3

Eigen is a C++ template library for linear algebra: matrices, vectors,
numerical solvers, and related algorithms.

use

ubuntu and with cmake

example

# install
sudo apt-get install libeigen3-dev

# cflags
pkg-config eigen3 --cflags
-I/usr/include/eigen3

# watch
ls -F /usr/include/eigen3/
Eigen/  signature_of_eigen3_matrix_library  unsupported/

note: cmake find package maybe not work well e.x. for ubuntu 14.04 ..
so see below
(TODO: find out where wrong!)

  • compile by cmake
find_package(Eigen3 REQUIRED)
if(NOT EIGEN3_INCLUDE_DIRS)
  find_package(PkgConfig REQUIRED)
  pkg_search_module(EIGEN3 REQUIRED eigen3)
endif()

# or
find_package(Eigen3)
if(NOT EIGEN3_INCLUDE_DIRS)
  message(STATUS "use EIGEN3_INCLUDE_DIRS: /usr/include/eigen3")
  set(EIGEN3_INCLUDE_DIRS /usr/include/eigen3)
endif()
  • by travis-ci

but env not work!

sudo: required
dist: trusty # 14.04

env:
  global:
    - Eigen3_DIR=/usr/lib/cmake/eigen3
before_install:
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libeigen3-dev -y ; fi

get

see also