Boost logo

Boost :

Subject: Re: [boost] [interprocess]why message_queue receive() will consume so much CPU resource
From: jon_zhou_at_[hidden]
Date: 2009-09-08 09:55:24


The code can trap in sched_yield (),(see below)

why it still consume high CPU resource?

(gdb) bt
#0 0xffffe410 in __kernel_vsyscall ()
#1 0x401b706c in sched_yield () from /lib/tls/libc.so.6
#2 0x0804e88f in thread_yield ()
    at ../boost138inst/include/boost-1_38/boost/interprocess/detail/os_thread_functions.hpp:1
04
#3 0x0804c22b in boost::interprocess::interprocess_condition::do_timed_wait (
    this=0x40018018, tout_enabled=false, abs_time=@0xbff77a70, mut=@0x40018014)
    at ../boost138inst/include/boost-1_38/boost/interprocess/sync/emulation/interprocess_cond
ition.hpp:125
#4 0x0804bfc2 in boost::interprocess::interprocess_condition::do_wait (this=0x40018018,
    mut=@0x40018014)
    at ../boost138inst/include/boost-1_38/boost/interprocess/sync/emulation/interprocess_cond
ition.hpp:70

-----Original Message-----
From: ZHOU,JON (A-China,ex2)
Sent: Tuesday, September 08, 2009 10:21 AM
To: boost_at_[hidden]; ZHOU,JON (A-China,ex2)
Subject: [interprocess]why message_queue receive() will consume so much CPU resource

Hi there

I just found that message_queue::receive() or message_queue:: timed_receive () consume high CPU
resource, (99% CPU) the code like the below:

//create message_queue

date d(2009,Sep,8); //an arbitrary date
//construct a time by adding up some durations durations
ptime t1(d, hours(0)+minutes(0)+seconds(1)+millisec(0));

while (1)
{
  for(int i = 0; i < 100; ++i){
    int number;
    //mq.receive(&number, sizeof(number), recvd_size, priority);
    mq.timed_receive(&number, sizeof(number), recvd_size, priority,t1);
  }
}

As I know, both the receive() & timed_receive() are block method, there should be sleep mechanism inside. why it still need so much CPU resource?

Thanks
jon


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