Jump to content
FPiette

Named pipe failure, multithreading and asynchronous I/O

Recommended Posts

This is an old thread.  However I have a question regarding Russell Libby's unit.

Has anybody used/tested TPipeConsole?  

 

TPipeConsole uses standard pipes (OpenStdPipes calls CreatePipe), but then uses PeekNamedPipe on theses pipes in ProcessPipe.  According to the documentation this is a blocking operation when used with anonymous pipes and the whole thing falls apart.  Question: is this the case - does PeekNamedPipe blocks with anonymous pipes or this is only an issue when multiple threads try to access the same pipe?

 

See also https://devblogs.microsoft.com/oldnewthing/20110707-00/?p=10223 by Raymond Chen

 

Edited by pyscripter

Share this post


Link to post

I Think I found two bugs in 64 bit mode:

procedure TSyncManager.RemoveThread(ThreadSync : TThreadSync);
var
    lpInfo : TSyncInfo;
begin
    // Enter critical section
    EnterCriticalSection(FThreadLock);

    // Resource protection
    try
        // Find the info using the base thread id
        lpInfo := FindSyncInfo(ThreadSync.SyncBaseTID);
        // Check assignment
        if Assigned(lpInfo) then
            PostMessage(lpInfo.FThreadWindow, CM_DESTROYWINDOW, 0,
//                Longint(lpInfo));           // old version
                LPARAM(lpInfo));              // my version
    finally
        // Leave the critical section
        LeaveCriticalSection(FThreadLock);
    end;
end;


procedure TSyncManager.Synchronize(ThreadSync : TThreadSync);
var
    lpInfo : TSyncInfo;
begin
    // Find the info using the base thread id
    lpInfo := FindSyncInfo(ThreadSync.SyncBaseTID);

    // Check assignment, send message to thread window
    if Assigned(lpInfo) then
//        SendMessage(lpInfo.FThreadWindow, CM_EXECPROC, 0, Longint(ThreadSync));     // old version
        SendMessage(lpInfo.FThreadWindow, CM_EXECPROC, 0, LPARAM(ThreadSync));        // my version
end;

 

Carsten

Share this post


Link to post

I registered just to thank you for these 2 lines:
thank you very much Carsten!!
 and of course the postcard will also go to Francois :)

//the problem mainly occurs under Win11

  • Like 1
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×