Wiki

Clone wiki

coco / usage

Using coco

To use coco, you must change your compiler’s include paths such that it sees the coco headers before the boost headers. You must also link against the coco library.

All of the Boost 1.34 stuff has been mirrored in coco except for the read/write mutex stuff, which the boost documentation recommends you avoid.

Headers

All of coco’s code lives inside namespace coco, but the build will create a set of “fake” boost headers under <buildroot>/<variant>/coco.fake_boost_headers.

// Copyright 2012 Edd Dawson.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef MUTEX_HPP_2308_03022012
#define MUTEX_HPP_2308_03022012

#include <coco/mutex.hpp>

namespace boost { using namespace coco; }

#endif // MUTEX_HPP_2308_03022008

So all the stuff in the coco namespace is pulled in to namespace boost when using the fake headers, allowing you to compile your existing boost threads code against coco rather than boost.

Context switches

Coco will context switch between "threads" in a cyclic fashion at the following times:

  • When a thread is created (context switches to the new thread)
  • When the body of a thread finishes
  • When a thread would block/wait when join()ing with another thread
  • When a thread would block/wait on a synchronization primitive (mutex, condition variable, barrier, etc)
  • When a thread calls a condition variable’s notify_one() or notify_all() member functions and there are waiting threads
  • When calling thread::sleep(xt) where xt is a time in the future
  • When calling thread::yield()

Native threads

I would advise against mixing coco with native (preemptive) threads at this stage.

Updated