mosjin / Boost.CMT

Cooperative Multitasking

Home Page:http://bytemaster.github.com/Boost.CMT/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boost.CMT - Cooperative Multitasking Library

This library builds on top of Boost.Context to provide an effecient coopertive multitasking API with a focus on ease of use and staying out of your way.

Some of the key features include:

  1. Lock-free inter-thread communication.
  2. Waiting on boost::signal
  3. Propagation of exceptions to wait() caller.
  4. Minimial useage of heap, synchronous inter-thread calls do not allocate on heap.
  5. Actor Paradigmn support via Boost.Reflect's any_ptr

Boost.CMT can be built by checking out my development repository: https://github.com/bytemaster/dev

Installation

git clone https://github.com/bytemaster/mace
cd mace
git submodule init
git submodule update
cmake .
make
make install
@endcode

Notice

This library is not part of the official Boost C++ library, but is written, to the best of my ability, to follow the best practices established by the Boost community and with the hope of being considered for inclusion with a future Boost release.

Warning

This code is in early alpha phase. I welcome feedback and help in defining the scope of this library.

Requirements

This code has been tested on Mac OS X using gcc 4.5.3 and boost 1.47

  1. Boost.Context is included.
  2. Boost.Atomic is included.
  3. Boost.Reflect is required for using Actors

Basic Example

int hello(const std::string& world ) {
    return world.size(); 
}

int main( int argc, char** argv ) {
    ptime start = microsec_clock::universal_time();
    int sum = 0;
    for( uint32_t i = 0; i < 1000; ++i ) 
        sum += async<int>( boost::bind(hello, "world"), "hello_func" ).wait();
    ptime end = microsec_clock::universal_time();
    slog( "%1% calls/sec", (1000.0/((stop-start).total_microseconds()/1000000.0)) );
}

Signal Example

boost::signal<void(std::string)> test_signal;

void delay()
{
    cmt::usleep(2000000);
    test_signal("hello world!");
}

int main( int argc, char** argv ) {
     async( delay );
     std::cerr<<cmt::wait(test_signal);
}

License

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following:

The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Cooperative Multitasking

http://bytemaster.github.com/Boost.CMT/


Languages

Language:C++ 92.4%Language:C 7.1%Language:CMake 0.5%