I'm replying here cos it's too much to do via /msg

gulden says We can clone filehandles, but can u ensure tha they share buffers, locks and son on?

On (native) Win32 & Win64 I'll give you a qualified yes. On the evidence of your posts, maybe not on other (POSIX) platforms.

To the best ability to track this through, the difference lies somewhere below this function in sv.c:

PerlIO * PerlIO_fdupopen(pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags) { #if defined(PERL_MICRO) || defined(__SYMBIAN32__) return NULL; #else #ifdef PERL_IMPLICIT_SYS return PerlSIO_fdupopen(f); #else #ifdef WIN32 return win32_fdupopen(f); #else if (f) { const int fd = PerlLIO_dup(PerlIO_fileno(f)); if (fd >= 0) { char mode[8]; #ifdef DJGPP const int omode = djgpp_get_stream_mode(f); #else const int omode = fcntl(fd, F_GETFL); #endif PerlIO_intmode2str(omode,mode,NULL); /* the r+ is a hack */ return PerlIO_fdopen(fd, mode); } return NULL; } else { SETERRNO(EBADF, SS_IVCHAN); } #endif return NULL; #endif #endif }

With the Win* versions complying with this description from the POSIX standard:

The object referenced by the descriptor does not distinguish betw +een fildes and fildes2 in any way. Thus if fildes2 and fildes are du +plicate references to an open file, read(2), write(2) and lseek(2) calls +all move a single pointer into the file, and append mode, non-blocking I/O + and asynchronous I/O options are shared between the references. If a + sepa- rate pointer into the file is desired, a different object referen +ce to the file must be obtained by issuing an additional open(2) call. + The close-on-exec flag on the new file descriptor is unset.

other (ironically POSIX) platforms not!

I'm guessing (on the basis of little more than gut feel and my abortive attempts to trace this through perlio.c, that the problem lies with the perlio implementation of the dup2 semantics rather than the underlying OSs (which would have noticed this much earlier).

If you compile your own Perl on one of those platforms, then you could try using stdio instead of perlio and confirm or not my suspicions. Alternatively, put together a simple testcase that demonstrates the problem (or use mine from above that works for me and fails for you), and raise a PerlBug.

As for locking: you don;t need to be able to share the filehandle in order to use locking. You declare a simple shared scalar and perform your locking on that.

Sorry that I cannot explain this better, nor help you with non-Win* platforms.


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.
RIP PCW

In reply to Re^9: Threads: How to share a FileHandle to Write by BrowserUk
in thread Threads: How to share a FileHandle to Write by gulden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.