[fpc-pascal] Inter-process communication, a cautionary tale

OBones obones at free.fr
Wed Jul 18 17:14:00 CEST 2012


Mark Morgan Lloyd wrote:
> Basically, what I was trying to do was this. In the main thread:
>
>     fIpcPipe:= CreateNamedPipe(PChar(fIpcName), PIPE_ACCESS_INBOUND,
>                         PIPE_TYPE_MESSAGE + PIPE_READMODE_MESSAGE,
>                                 1, 0, 0, 1000, NIL (* @sa *) );
>
> That works. Fire up a background reader thread, and make sure that the 
> main thread doesn't proceed...
So you are not creating the "read" pipe in the context of the thread 
that actually reads from it?
I'm not sure that this is actually supported, maybe you should try to 
create it in the context of the reading thread.

Further to this, I don't see the usage for Suspend. I mean, why suspend 
the reading thread? Or maybe I misunderstood what TSphinxThread is. And 
yes, Suspend is deprecated, but for VERY good reasons, as it can 
actually suspend your thread in the middle of an API call, and that is 
VERY dangerous.

And last, I would not use the sleep look but a simple TEvent to notify 
the main thread that the reader thread is ready. Much more efficient.



More information about the fpc-pascal mailing list