[Gambas-user] open named pipe never returns

Tobias Boege taboege at gmail.com
Mon Nov 19 10:20:57 CET 2018


On Sun, 18 Nov 2018, Steve via User wrote:
> The statement
> 
> hfile = open pipe "/tmp/mypipe01" for watch  (or for read) never returns
> (acts like deadlock).
> 
> It does actually create the pipe.
> 
> Does gambas use fopen internally for access?  I get the same behavior in C
> if fopen is used instead of open.
> 
> There is a restriction:
> 
> *Restriction:* If fopen() is used to open named pipes in a multi-threaded
> environment, a deadlock will occur. This deadlock is caused by a named pipe
> waiting for the other end of the pipe to be opened, while still holding the
> fopen() multi-thread mutex. To prevent this deadlock, use open() to open the
> named pipe, instead of fopen().
> 

That is not the reason as Gambas is not multi-threaded, but the reason is
inside that text you quoted. Opening a named pipe blocks the process until
the pipe is opened for writing from somewhere else. A blocking operation
is very different from a deadlock. Your program can advance, but it depends
on the mercy (or your instruction) of another process to open the other
end of the pipe.

This is the relevant excerpt from the Gambas documentation:

  However, a pipe has to be open at both ends simultaneously,
  before you can proceed to do any input or output operations
  on it. Opening a pipe for reading normally blocks until some
  other process opens the same pipe for writing.

It is actually an excerpt of the mkfifo(3) man page, so this is completely
normal behaviour. Internally, Gambas uses mkfifo() followed by a normal
open() to create a pipe Stream object, to answer your actual question,
and not what I think your question should have been :-)

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list