in reply to Re^2: Threads: How to share a FileHandle to Write
in thread Threads: How to share a FileHandle to Write

It looks like your C-runtime libraries or Perl implementation is broken(1).

I cannot reproduce your results on my platform:

The only logical thing for CLONE to do for an open filehandle is dup() or dup2(), and according to the man pages for those calls:

NAME dup, dup2 - duplicate a file descriptor SYNOPSIS #include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); DESCRIPTION dup and dup2 create a copy of the file descriptor oldfd. After successful return of dup or dup2, the old and new descrip +tors may be used interchangeably.
They share locks, file position pointers and flags; for example, if the file position is modified by using lseek on one of the descriptors, the position is also changed for the other.
The two descriptors do not share the close-on-exec flag, howeve +r.

1. That is, your platform is exhibiting unspecified--thought clearly defined--behaviour.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: Threads: How to share a FileHandle to Write
by gulden (Monk) on May 19, 2009 at 14:45 UTC
    I've tested in more than one SO, and the problem is the same. Try to increase the number of threads, in order to increase concurrency and you will get the same result.
      I've tested in more than one SO, and the problem is the same. Try to increase the number of threads, in order to increase concurrency and you will get the same result.

      Here is one copy running 1000 concurrent threads:

      C:\test>junk4 -NTHREADS=1000 STOP: Tue May 19 16:26:26 2009 1000000 1242746771.5932.out

      And this is 20 concurrent copies each running 100 concurrent threads each:

      C:\test>for /l %i in ( 1,1,20 ) do @start /b junk4 -NTHREADS=100 STOP: Tue May 19 16:07:35 2009 100000 1242745650.6976.out STOP: Tue May 19 16:07:35 2009 100000 1242745651.0876.out STOP: Tue May 19 16:07:36 2009 100000 1242745651.15.out STOP: Tue May 19 16:07:37 2009 100000 1242745651.7896.out STOP: Tue May 19 16:07:48 2009 STOP: Tue May 19 16:07:48 2009 STOP: Tue May 19 16:07:49 2009 STOP: Tue May 19 16:07:50 2009 STOP: Tue May 19 16:07:51 2009 STOP: Tue May 19 16:07:51 2009 STOP: Tue May 19 16:07:51 2009 STOP: Tue May 19 16:07:51 2009 STOP: Tue May 19 16:07:52 2009 STOP: Tue May 19 16:07:52 2009 STOP: Tue May 19 16:07:52 2009 STOP: Tue May 19 16:07:52 2009 100000 1242745654.972.out 100000 1242745654.8784.out 100000 1242745656.0952.out STOP: Tue May 19 16:07:52 2009 STOP: Tue May 19 16:07:52 2009 STOP: Tue May 19 16:07:52 2009 STOP: Tue May 19 16:07:52 2009 100000 1242745656.142.out 100000 1242745656.1576.out 100000 1242745657.1092.out 100000 1242745657.1716.out 100000 1242745657.9048.out 100000 1242745657.5304.out 100000 1242745657.3432.out 100000 1242745657.2652.out 100000 1242745656.5476.out 100000 1242745655.596.out 100000 1242745655.8768.out 100000 1242745654.7536.out 100000 1242745654.3012.out

      Nary a whiff of a problem. Still unconvinced it works fine here?

      Is that other OS (I assume that's what you meant by SO?), based on the same kernel? Or compiled against the same CRT? Or both?


      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've tested in this PCs:

        PC 1

        -bash-3.00$ uname -a SunOS reia 5.10 Generic_137137-09 sun4v sparc SUNW,Sun-Blade-T6320 -bash-3.00$ perl -Mthreads -e 'print $threads::VERSION . "\n"'; perl +-Mthreads::shared -e 'print $threads::shared::VERSION . "\n"' ; perl +-v 1.71 1.27 This is perl, v5.8.8 built for sun4-solaris-thread-multi
        PC 2
        -bash-3.00$ uname -a SunOS deimos 5.10 Generic_138889-03 i86pc i386 i86pc -bash-3.00$ perl -Mthreads -e 'print $threads::VERSION . "\n"'; perl - +Mthreads::shared -e 'print $threads::shared::VERSION . "\n"' ; perl - +v 1.72 1.28 This is perl, v5.8.8 built for i86pc-solaris-thread-multi
        PC 3
        $ uname -a Linux communicator 2.6.27-11-generic #1 SMP Wed Apr 1 20:57:48 UTC 200 +9 i686 GNU/Linux $ perl -Mthreads -e 'print $threads::VERSION . "\n"'; perl -Mthreads:: +shared -e 'print $threads::shared::VERSION . "\n"' ; perl -v 1.67 1.14 This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
        What do you mean by CRT?