iic has asked for the wisdom of the Perl Monks concerning the following question:

pipe() --- "Note that if you set up a loop of piped
processes, deadlock can occur unless you are very careful."

What is the meaning and what should I do?Thank you.

Replies are listed 'Best First'.
Re: help me understand it please
by merlyn (Sage) on Apr 30, 2000 at 18:48 UTC
    If you are both sending to and receiving from a process, you must realize that there's only an 8K buffer in each direction. So if you are writing to the other process, and send more than 8K, your process will stop and wait for the other process to start reading. But suppose it has done the same thing, trying to send you more than 8K from a previous response! Now you have two processes in deadlock.

    As to how to solve it, the quickest general answer is "careful programming". If that doesn't make sense to you, then don't attempt it.

    -- Randal L. Schwartz, Perl hacker

Re: help me understand it please
by lhoward (Vicar) on May 01, 2000 at 02:13 UTC
    Probably the simplest example of a deadlock is when a process (A) is waiting on data from process B before it can continue. At the same time process B is waiting on data from process A before it can continue. Both processes are waiting on each other, and neither will ever move forward. Deadlocks generally occur in much more complicated scenarios. Deadlocks occur when multiple processes are waiting for resources (IO ports, data from other processes, etc...) and already have some resources allocated to them that they will not free up until they get the new resources they need. Deadlocks aren't very common at an application level, but OS programmers must be very careful to avoid them.