[Ace-users] [ace-users] how to force svc() to wait for the std::queue to fill up?

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Thu Oct 25 14:29:50 CDT 2007

Hi Bob,

To ensure that we have proper version/platform/compiler information,
please make sure you fill out the appropriate problem report form
(PRF), which is in


or in


in older versions of ACE+TAO.  Make sure to include this information
when asking any questions about ACE+TAO since otherwise we have to
"guess" what version/platform/compiler/options you've using, which is
very error-prone and slows down our responsiveness.  If you don't use
the PRF, therefore, it is less likely that someone from the core
ACE+TAO developer team will be able to answer your question.
Naturally, we encourage and appreciate other members of the ACE+TAO
user community who can respond to questions that they have the answers

>I have a task class which inherits MyTask : public
>ACE_Task<ACE_MT_SYNCH>. In my svc() I have a loop
>int MyTask::svc()
>	ACE_OS::sleep(1);
>	while( !myQueue.empty() )
>	{
>                    // do something
>                    if( myQueue.size() == 0 )
>	             break;
>	}
>	return 0;
>I do a wait() in the destructor.
>Things work fine if I sleep(), however if I do not the queue is not
>filled up and svc exits.
>Unfortunately I cannot use ACE_Message_Block() - I cannot serlialize
>my object.
>Is there any other way to get arround this problem without sleep()?

I think the heart of the problem here is that std::queue() is
non-synchronized.  It's not really clear what you are trying to do,
but you should probably take a look at the discussion of
ACE_Condition_Thread_Mutex in Chapter 10 of C++NPv1
<www.cs.wustl.edu/~schmidt/ACE/book1/>.  Naturally, the easiest thing
to do would be to simply use the ACE_Message_Queue that's part of
ACE_Task, as per the discussion in Chapter 6 of C++NPv2


Dr. Douglas C. Schmidt                       Professor and Associate Chair
Electrical Engineering and Computer Science  TEL: (615) 343-8197
Vanderbilt University                        WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203                          NET: d.schmidt at vanderbilt.edu

More information about the Ace-users mailing list