Boost logo

Threads-Devel :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-05-20 21:00:53


Hello,

First of all bravo,

I find that subject should be non-preemptible threads. I think that your
library in its own is a very good candidate to Boost.

----- Original Message -----
From: "Edd Dawson" <lists_at_[hidden]>
To: <threads-devel_at_[hidden]>
Sent: Tuesday, May 20, 2008 11:57 PM
Subject: [Threads-devel] Single threaded implementation of Boost.Thread

> Hello,
>
> A while back I put together a library[1] with the same interface as
> Boost.Thread that I use for testing purposes, as it's nice to be able
> to test algorithmic logic in isolation from synchronization logic.
>
> The implementation is cooperative, rather than preemptive, written in
> terms of Fibers on Windows and the <ucontext.h> functionality on POSIX
> systems.
>
> I started thinking about bringing the code up to date in order to
> mirror the new 1.35 interface, when I realized that I hadn't mentioned
> my library here before.
>
> Would this cooperative version of Boost.Thread be useful for boosters
> in general? Regardless, someone here may find it useful!

Yes I really think so. IMO you should also request interest in the boost
developement list.

> Kind regards,
>
> Edd
>
> [1] http://www.mr-edd.co.uk/?page_id=91

I have not taken a deep look yet, but I suspect a variation of the fiber
conext can be used to implement deterministic alternation.

I'm wondering if using a variation of the fiber conext can be used to
implement deterministic alternation.
and writing something like:

class TrafficLight : public alternating_component {
    color::type state_;
public:
    TrafficLight() : state_(color::red) {}
    void body() {
        for(;;) {
            state_ = color::red;
            yield();
            state_ = color::green;
            yield();
        }
    }
};
class Controller {
    TrafficLight& north_, south_;
public:
    Controller(TrafficLight& north, TrafficLight& south) :
    void operator() () {
        north_(); // north.state_==red
        south_();
        south_(); // south.state_==green
        for(;;) {
            // wait some time
            sleep(2);
            // switch the states
            south_();
            north_();
        }
    }
};

What do you think?

A non-premptible thread will be a particular case of alternating_component
scheduled by a specific scheduler.
Do you have some performances messures?

It is a pity that xcontext.h is obsolete and that this header file is
missing from gnulib on some platforms as OpenBSD 3.8, Cygwin, mingw, BeOS.

The Boost.Coroutine library use also xcontext.h .

Best regards

_____________________
Vicente Juan Botet Escriba


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk