0

I'm using GCC 4.4.7 (does not have all the C++ 11 stuff yet) and Boost 1.55 on Centos 6.2. This is NOT a homework or class assignment.

A third party library calls back into my application. This function is invoked on a single thread and my job is to process the message and return as fast as possible

void mycallback(Message& m)
{
    /// process m here and return quickly
    doProcessing(m);
}

Now we have a requirement to delay processing of certain messages based on an attribute in the message.

We still need to return control to the third party library as fast as possible but internally I want to hang on to the message for, say, 1 second, before processing it

void mycallback(Message& m)
{
    if(m.type == 1) {    
       doProcessingInOneSecond(m);
    }
    else {
       doProcessing(m);
    }
}

I just want to get some ideas as to a good way to approach this from the community. The constraints are that

1. the callback needs to return as quickly as possible in all cases
2. the callback may be invoked many times per second (always on the same thread)
3. messages of the same type must always be processed sequentially
rc1
  • 341
  • 3
  • 7
  • 17
  • 1
    `doProcessingInOneSecond(m);` this is asking for threading. Since you don't have c++ 11. You need to use some other library like `pthreads` or maybe OpenMP. It the message types are known ahead, you can make a map of queues. – luk32 Mar 20 '15 at 14:38
  • The `doProcessingInOneSecond` is a processing to be done in background if you want the callback to terminate immediately. You should consider using threads to handle that. – chmike Mar 20 '15 at 14:39
  • It's doable without threading. I've been doing things likes using Qt::QueuedConnection. Basically instead of running `doProcessingInOneSecond(m)` at the point of call, you want to push in the event queue of its enclosing thread and continue, so that when `mycallback(Message& m)` finishes, next thing in queue, which is `doProcessingInOneSecond(m)` gets called. http://stackoverflow.com/questions/29150610/is-there-a-way-to-declared-a-qt-signal-that-can-only-be-listened-in-within-enclo – user3528438 Mar 20 '15 at 15:40

0 Answers0