Re: Three processes intercommunicating(both ways) using pipes, (six pipes??)

From: Pascal Bourguignon (spam_at_mouse-potato.com)
Date: 11/27/05


Date: Sun, 27 Nov 2005 17:19:29 +0100


"mirtoni" <mirton@gmail.com> writes:

> Thanx for the reply, but I'm sorry cause I have no idea what you wrote
> above. Is this some kind of pseudo-code.

Yes.

> I really appreciate the help,
> but I'm not good at low-level programming languages.

That's why I wrote higher level pseudo-code.

> While I was waiting for a reply I tried something like this:
>
> Two pipes to which the server process reads and writes to.
> And on the other end The Client and Process 3 will read and write to.
> This is because the information going through the pipes from one
> process will be the same for the other two processes.
> So when the server writes, he will have to write it twice with a little
> usleep(300) in between. And if one of the other processes writes, then
> the server will have to re-route the data to the other process!!!
>
> I still haven't got it going completely, but I hope you can offer me a
> better solution with identical information in pipes besides the one I
> wrote above..

Divide and conquer.
and abstract, abstract, abstract!

That means, don't try to solve several problems at once.

The fact that you consider a process being a server and the others
clients is irrelevant once you've specified you want them to
communicate in a ring of pipes: write a function that just builds this
ring of pipe.

Don't think your server as writting twice. Abstract! Have it write
once, and let the implementation deal with what is needed to have all
recipients receive the data. That means, instead of writting:
   write(pipe[WRITE],...);
write:
   tell_them(...);
and let the tell_them() function do what needs to be done.

Now, writting twice (or more, what will happen when you'll have 10
processes?!), may not be the most efficient way to multicast data to
processes on the same computer. You could try shared memory (with
semaphores). Then the tell_them() function would copy the data once
to a shared memory block, and increment a semaphore by the count of
recipients. The recipients will then be able to read the data
directly from the shared memory block, and decrement the semaphore.
When the semaphore reaches 0, all recipient processes have read the
data and the shared memory block can be reused for the next message.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Cats meow out of angst
"Thumbs! If only we had thumbs!
We could break so much!"


Relevant Pages

  • Re: Task goes into a Pend+I state : Semaphore issue?
    ... All this while the other task pends on the semaphore by doing a ... (I now have it coded in my code, to tun that test case, that the server ... I need to clear up the command that might be being ... The fundamental behavior of the mutual-exclusion semaphore is identical ...
    (comp.os.vxworks)
  • Re: Task goes into a Pend+I state : Semaphore issue?
    ... My semaphore is a counting semaphore, ... The task B, when reads the message in the message queue, replies back. ... The trouble usually arises when the server snaps connection abruptly. ... I need to clear up the command that might be being ...
    (comp.os.vxworks)
  • Re: Login failed for user sa. (Error code: 18456).
    ... Try to disable named pipes just to get it out of the equation... ... SharePoint Server is behind the ... firewall and SQL Server Server is in the domain. ... >> "Robert Bogue" wrote: ...
    (microsoft.public.sharepoint.portalserver)
  • Re: ncpfs: Connection invalid / Input-/Output Errors
    ... >> while the other server does not. ... > You need either another CPU, or semaphore which do not suffer from ... I found out that my attemption were true: the plugin really gets a KILL ... Means that the nagios check plugin is ...
    (Linux-Kernel)
  • Re: Inter process Semaphore possible?
    ... > I ish to be able to limit the number of concurrent requests to the server. ... HANDLE hSem = CreateSemaphore; ... Both Process A and Process B now have a handle to the same semaphore. ...
    (microsoft.public.vc.mfc)