Boost logo

Boost :

Subject: [boost] [tasklet] micro-tasks with cooperative scheduler
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2011-03-18 18:47:22


Hi,

I've uploaded version 0.2.0 of boost.tasklet:
http://www.boostpro.com/vault/index.php?action=downloadfile&filename=boost.tasklet-0.2.0.zip&directory=Concurrent%20Programming&

boost.tasklet provides a framework for cooperatively scheduling
micro-tasks (some kind of user-level threads).
It comes with an scheduler, synchronisation primitives - mutex,
condition, barrier, event-variables (auto- and manual-reset and
count-down variable), future and channel.

boost::tasklets::packaged_task< std::string > pt( helloworld_fn);
boost::tasklets::unique_future< std::string > fu = pt.get_future();
boost::tasklet t( boost::move( pt), boost::tasklet::default_stacksize);

boost::scheduler::schedule( t);
boost::scheduler::schedule( my_function, 1, "abc");
for (;;)
{
    while ( boost::scheduler::run() );
    if ( boost::scheduler::empty() ) break;
}

std::cout << fu.get() << std::endl;

In order to let functions/actions be executed in a separate thread
boost.tasklet provides a scheduler_thread:

boost::scheduler_thread st;

boost::shared_future< void > f1( st.schedule( some_fn ) );
boost::shared_future< std::string > f2( st.schedule( other_fn) );

  f1.wait();
  std::cout << "future 2 result: " << f2.get() << std::endl;

regards,
Oliver


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk