[Gambas-user] open named pipe never returns

Steve stevjensen at aol.com
Mon Nov 19 17:05:44 CET 2018




-------- Forwarded Message --------
Subject: 	Re: [Gambas-user] open named pipe never returns
Date: 	Mon, 19 Nov 2018 10:33:42 -0500
From: 	Steve <stevjensen at aol.com>
To: 	Tobias Boege <taboege at gmail.com>



Ok. The question is: How do I randomly communicate back to gambas with
data? Perhaps more accurately: How do I raise an event in gambas from C
library code.

 From an extern C function I can callback to gambas while the function
is being called from gambas.

When this same external C function gets a signal it crashes with a
segmentation fault(11) when attempting to call the same gambas function
again and from the same thread the initial successful call was made from.

Note: This works quite nicely in VB6  with the caveat that you can not
do anything to the code while the callback trigger is active. It still
executes regardless of if the IDE is in run or stop mode.


On 11/19/2018 4:20 AM, Tobias Boege wrote:
> 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
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20181119/ff55246a/attachment-0001.html>


More information about the User mailing list