Question

I'm trying to use the Boost::lockfree::spsc_queue for an application that will be supported on multiple platforms. I tried the spsc_queue.cpp example from boost_1_55_0/libs/examples/lockfree on Windows 7 using various versions of Visual Studio, and they all work fine. It also works perfectly fine on CentOS 6.3 (running under VMWare Player 6.0). But on Centos 5.3, using gcc 4.1.2 (also running under VMWare) the performance is unacceptable - it's about 200 times slower than on CentOS 6.3. I need to support all of those OS's and compiler versions, despite the fact they are so old they are no longer supported.

Does anyone have any ideas why it's so slow on CentOS 5.3?

Was it helpful?

Solution

Thanks for the useful comments following my question. I've now figured out that the poor performance is due to the way threads get scheduled on RHEL 5 on a VM that only uses one of my CPU cores. The issue goes away when using multiple cores, and also for a single core the following modification to the Boost example (i.e. making the producer sleep a short time when the queue is full) greatly improves overall speed:

void producer(void)
{
    for (int i = 0; i != iterations; ++i) {
        int value = ++producer_count;
        while (!spsc_queue.push(value))
            usleep(1000);            // WAS: ; (empty statement)
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top