CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    1,342

    Semaphore timeout while using pipes?

    I'm using named pipes two communicate between two processes on the same computer. Quite frequently (and randomly), however, a ConnectNamedPipe() operation fails and GetLastError() returns 121, which according to MSDN is due to a semaphore timeout. Can someone explain what pipes have to do with semaphores and why I could be getting this error?

    EDIT: Sorry, I made a mistake. It is CreateFile(), not ConnectNamedPipe(), that produces the error.
    Last edited by HighCommander4; September 25th, 2006 at 05:53 PM.
    Old Unix programmers never die, they just mv to /dev/null

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757

    Re: Semaphore timeout while using pipes?

    one process creates the named pipe via CreateNamedPipe() and waits for clients via ConnectNamedPipe(). are there multiple connections to the pipe created in the first process on the second process?

    Kuphryn

  3. #3
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    1,342

    Re: Semaphore timeout while using pipes?

    Quote Originally Posted by kuphryn
    one process creates the named pipe via CreateNamedPipe() and waits for clients via ConnectNamedPipe(). are there multiple connections to the pipe created in the first process on the second process?

    Kuphryn
    The second process keeps connecting to and disconnecting from the first process' pipe using CreateFile() and CloseHandle(). It is CreateFile() in the second process that produces the error code 121 frequently, usually after connecting and disconnecting multiple times.
    Old Unix programmers never die, they just mv to /dev/null

  4. #4
    Join Date
    Feb 2002
    Posts
    5,757

    Re: Semaphore timeout while using pipes?

    logic is correct. multiple threads? possible that you open more pipes than close pipe?

    Kuphryn

  5. #5
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    1,342

    Re: Semaphore timeout while using pipes?

    Quote Originally Posted by kuphryn
    logic is correct. multiple threads? possible that you open more pipes than close pipe?

    Kuphryn
    Nope, both processes are single-threaded. The use of pipes is well encapsulated in functions that start by connecting the pipe and end by disconnecting it, so I'd say it's unlikely I open the pipes more than I close them.

    I changed my code to decrease the number of connects/disconnects, preferring to stay connected until a larger amount of data is transferred, and the errors have significantly decreased in frequency, but still come up once in a while and undermine the reliability of my code.

    I'm wondering if it has something to do with the amount of pipe instances I'm allowing when I'm creating the pipe, though I'm not sure how that could be the problem since the pipes are only being used between two processes...

    EDIT: I have increased the number of allowed pipe instances that I specify at the time of pipe creation, but it had no effect. The errors continue to appear very randomly.
    Last edited by HighCommander4; September 28th, 2006 at 03:10 PM.
    Old Unix programmers never die, they just mv to /dev/null

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured