Boost logo

Boost :

Subject: Re: [boost] [context review] Performance questions
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2012-01-09 13:54:50


2) Can we use contexts like condition variables? Can we make something
like this:

struct task{
   // Implementanion
};

std::deque<task> g_tasks;
continuation g_cont;
boost::thread::mutex g_mutex;

// Executes ready tasks
void thread_1() { // This function will be run in thread #1
    while(1) {
        scoped_lock lock(g_mutex);
        if (g_tasks.empty()) {
            lock.unlock();
            g_cont.suspend();
        } else {
            auto t = g_tasks.front();
            g_tasks.pop_front();
            lock.unlock();

            t.run();
        }
    }
}

// Generate tasks
void threads_2_n() { // This function will be run in threads #2, #3 ...
    while(1) {
        // Generating task t
        task t;
        t.generate();

        scoped_lock lock(g_mutex);
        g_tasks.push_back(t);
        lock.unlock();
        g_cont.resume();
    }
}

Will there be some performance gains, because there is no more system
calls for condition variables?

If answer is yes for 2), then it is a killer feature and I will vote
YES and write a more detailed review.

P.S.: Sorry for two mails, instead of one.

Best regards,
Antony Polukhin


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