How to implement optional delayed processing
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
链接地址: http://www.djcxy.com/p/60532.html
上一篇: C ++
下一篇: 如何实现可选的延迟处理