Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi chris212,

At the time of my last reply, I didn't realize you had made an update. Disclaimer: Oh, btw, I'm not here to push MCE. Please use the module of your liking. Depending on the OS and/or number of workers, MCE::Mutex may run faster than Thread::Semaphore.

Thread::Semaphore

use strict; use warnings; use threads; use Thread::Semaphore; use MCE::Shared; use Time::HiRes 'time'; my $condvar = MCE::Shared->condvar; my $sem = Thread::Semaphore->new; # Start the shared server. Not necessary if Perl has IO::FDPass. MCE::Shared->start; sub test { $condvar->wait; for (1..10000) { threads->yield; $sem->down; $sem->up; } } threads->create('test') for 1..3; $condvar->broadcast(0.5); my $start = time; $_->join for threads->list; printf "duration: %0.03f secs\n", time - $start;

MCE::Mutex::Channel

use strict; use warnings; use threads; use MCE::Mutex; use MCE::Shared; use Time::HiRes 'time'; my $condvar = MCE::Shared->condvar; my $mutex = MCE::Mutex->new; # Start the shared server. Not necessary if Perl has IO::FDPass. MCE::Shared->start; sub test { $condvar->wait; for (1..10000) { threads->yield; $mutex->lock; $mutex->unlock; } } threads->create('test') for 1..3; $condvar->broadcast(0.5); my $start = time; $_->join for threads->list; printf "duration: %0.03f secs\n", time - $start;

MCE::Mutex::Flock

use strict; use warnings; use threads; use MCE::Mutex; use MCE::Shared; use Time::HiRes 'time'; my $condvar = MCE::Shared->condvar; my $mutex = MCE::Mutex->new( impl => 'Flock' ); # Start the shared server. Not necessary if Perl has IO::FDPass. MCE::Shared->start; sub test { $condvar->wait; for (1..10000) { threads->yield; $mutex->lock; $mutex->unlock; } } threads->create('test') for 1..3; $condvar->broadcast(0.5); my $start = time; $_->join for threads->list; printf "duration: %0.03f secs\n", time - $start;

Results

My laptop is a late 2013 Macbook Pro, 2.6 Ghz i7 quad CPU. Each virtual machine is configured with 4 cores.

* 3 threads: CentOS Linux 7.3

Thread::Semaphore 0.386 secs MCE::Mutex::Channel 0.162 secs MCE::Mutex::Flock 0.144 secs

* 3 threads: Windows 7

Thread::Semaphore 0.293 secs MCE::Mutex::Channel 0.499 secs MCE::Mutex::Flock 0.498 secs

* 20 threads: CentOS Linux 7.3

Thread::Semaphore 41.897 secs MCE::Mutex::Channel 0.980 secs MCE::Mutex::Flock 0.702 secs

* 20 threads: Windows 7

Thread::Semaphore 35.521 secs MCE::Mutex::Channel 2.994 secs MCE::Mutex::Flock 3.322 secs

Regards, Mario


In reply to Re: PerlIO file handle dup by marioroy
in thread PerlIO file handle dup by chris212

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2019-05-25 23:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you enjoy 3D movies?



      Results (152 votes). Check out past polls.

      Notices?
      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!