in reply to Re: threads + sockets stalling question
in thread threads + sockets stalling question

Hm. The problem comes down to the fact that PerlIO calls the crt fstat() in order to determine if the file descriptor it is trying to clone, is attached to a "regular file".

As the file descriptor in question is currently in an accept state in another thread and the CRT serialises access, the fstat blocks. The entire Perl_clone() blocks, and the client threads are never started.

When I connect to the listener from an external process, the accept completes, which unlocks the file descriptor. Thus the fstat() returns allowing the Perl_clone to complete and the client threads get created.

The real problem here seems to be the hookey methods used inside PerlIO. There has to be a better way than to try to fstat() a socket, to determine if it is socket.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"
  • Comment on Re^2: threads + sockets stalling question

Replies are listed 'Best First'.
Re^3: threads + sockets stalling question
by Corion (Patriarch) on Mar 17, 2010 at 14:53 UTC

    Comments in win32sck.c led me to GetFileType(), which might be all that's needed, at least to find out whether a file handle might be a socket.

    As the code is Win32-specific, and Windows 9x isn't supported anymore, this call could maybe used instead of fstat.

      That's a good idea. Unfortunately, I think that the problems go much deeper than I've yet discovered.

      If you stop the code from calling fstat(), it runs on a bit further before hanging again. This time it calls the CRT ftell() on a socket, which blocks because of the lock applied in the accept call. And if you fix that ....

      I tried (more in hope than expectation), that compiling without USE_PERLIO and/or enabling USE_PERLCRT might avoid some of the show stoppers in PERLIO, but it seems that Perl has become dependant upon PerlIO now :(


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Seems to me the real problem is not that fstat and ftell lock the CRT (since they only do so transiently), it's that accept locks the CRT (since it does so for an extended period of time). Is it possible to recode accept to avoid the CRT?