Boost logo

Boost :

Subject: Re: [boost] [context review] Several Questions
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2011-03-21 09:18:15


> > sched_yield(): 2108 cycles
> > ucontext_t: 1795 cycles
> > fcontext_t: 156 cycles
> >

> Actually it is quite consistent with what you had show,
> the Boost.Context is better (but not significantly) then
> real OS (kernel) context switch.

factor 13x ?

> It would be very useful to see real usability cases. Because otherwise
> it is hard to estimate usefulness of this library

The lib is intended to be a building block for higher abstractions like coroutines.

> I understand, it may be useful for "yeild" like iterators and so
> but it is not clear how does it work and what is the advantage
> in comparison to ordinary event driven approach.

I remember that factor (http://factorcode.org/) does context switching for its internal working.

You can preserve local data:

void myfunc()
{
   std::string s = "abc";
   for ( int i = 0; i< 10; ++i)
   {
      if ( 5 == i)
        // jump out to another code path not related to myfunc()
        // and preserve value of i and s
        yield();
        // if we jumped back we return from yield i==5, s == "abc"
      }
}

reagrds,
Oliver

-- 
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl

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