Boost logo

Boost :

Subject: [boost] [threads / signals2] Win events replace by boost signals (threadsafe)
From: Fu ji (fujimailing_at_[hidden])
Date: 2015-03-23 04:55:00


Hello,

I have to change win32 events with something portable so I decided to use
boost.signals2.

Right now I have something like:

ret = WaitForMultipleObjets{
    switch(ret)
    {
        case Timeout: something; break;
        case Event1: something; break;
        case Event2: something; break;
    }}

and I think that the good idea is to replace this with something like that:

for(;;){
    Execute code from timeout, if event occurs interrupt and execute
    code which is responsible for event handling}

but for test I write this:

boost::signals2::signal<void()> signal;

void SendSignal()
{
        std::cout << "Send signal";
        boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
        signal();
        boost::this_thread::sleep_for(boost::chrono::milliseconds(2000));
}

int main()
{
        boost::thread t1(SendSignal);

        for (;;)
        {
                std::cout << ".";
                boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
        }

        auto c = signal.connect([]()
        {
                std::cout << "Signal receive" << std::endl;
                boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
        });

        return 0;
}

unfortunately this example is not working, what I've done wrong ?

Best regards


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