[Ace-users] [ace-users] Different Reactors for reading and writing

Gonzalo Diethelm gonzalo.diethelm at diethelm.org
Wed Feb 6 11:27:12 CST 2008


     ACE VERSION:
         5.4.7

     HOST MACHINE and OPERATING SYSTEM:
         Ubuntu linux 2.6.22 (7.10)

     THE $ACE_ROOT/ace/config.h FILE:
         config-linux.h

     AREA/CLASS/EXAMPLE AFFECTED:
         ACE_Reactor

     DOES THE PROBLEM AFFECT:
         COMPILATION? No
         LINKING? No
         EXECUTION? Yes

     SYNOPSIS:

Hello everyone, greetings from Chile after a loong absence...

This is more a question to enlighten my ignorance, than a proper problem
report... I have a single-threaded process that intends do do this:

1. Have an ACE_Acceptor and an ACE_Connector.

2. The ACE_Connector will connect to the ACE_Acceptor using
   non-blocking IO (one thread). A Reader and Writer (both
   inheriting from ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>)
   will be created.

3. There will be an ACE_Message_Queue<ACE_MT_SYNCH> on which the Writer
   will enqueue messages and from which Reader will dequeue messages.
   This will happen in random order.

The problem I am seeing is that if the Writer hits the queue high
watermark, the call to enqueue() will simply block; this will not be
good, since the Reader (running on the same thread) will never get the
chance to dequeue a message and make more space for the Writer to go on.

One solution for this could be to query whether the queue is_full()
before trying to enqueue another message, but that just moves the flow
control issue somewhere else. Then I thought about maybe using two
Reactors running on two separate threads, one for the Acceptor / Reader
and one for the Connector / Writer. My questions are:

1. Is this the proper way to handle this situation? Is it correct to
   assume that if I want the Acceptor / Reader to run on a separate
   thread from the Connector / Writer, then I must have two separate
   Reactors, one for each of them? If I am wrong and I could have a
   single Reactor running on two threads, how would I set the
   Reactor's owner?

2. Is it Ok to have more than one Reactor on a single program? Will I
   run into problems if I go this way?

3. Are there any other suggested ways to handle this use case? Could the
   TP_Reactor play any part in this?

Thanks and best regards,

-- 
Gonzalo Diethelm
gonzalo.diethelm at diethelm.org



More information about the Ace-users mailing list