GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MCE::MUTEX (3)

.ds Aq ’

NAME

MCE::Mutex - Locking for Many-Core Engine

CONTENTS

VERSION

This document describes MCE::Mutex version 1.703

SYNOPSIS



   use MCE::Flow max_workers => 4;
   use MCE::Mutex;

   print "## running a\n";
   my $a = MCE::Mutex->new;

   mce_flow sub {
      $a->lock;

      ## access shared resource
      my $wid = MCE->wid; MCE->say($wid); sleep 1;

      $a->unlock;
   };

   print "## running b\n";
   my $b = MCE::Mutex->new;

   mce_flow sub {
      $b->synchronize( sub {

         ## access shared resource
         my ($wid) = @_; MCE->say($wid); sleep 1;

      }, MCE->wid );
   };



DESCRIPTION

This module implements locking methods that can be used to coordinate access to shared data from multiple workers spawned as processes or threads.

The inspiration for this module came from reading Mutex for Ruby.

API DOCUMENTATION

    MCE::Mutex->new ( void )

Creates a new mutex.

Channel locking is through a pipe or socket depending on platform. The advantage of channel locking is not having to re-establish handles inside new processes or threads.

CW$m->lock ( void )

Attempts to grab the lock and waits if not available. Multiple calls to mutex->lock by the same process or thread is safe. The mutex will remain locked until mutex->unlock is called.

CW$m->unlock ( void )

Releases the lock. A held lock by an exiting process or thread is released automatically.

CW$m->synchronize ( sub { ... }, CW@_ )

Obtains a lock, runs the code block, and releases the lock after the block completes. Optionally, the method is wantarray aware.



   my $value = $m->synchronize( sub {

      ## access shared resource

      value;
   });



INDEX

MCE, MCE::Core

AUTHOR

Mario E. Roy, <marioeroy AT gmail DOT com>
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MCE::MUTEX (3) 2016-03-20

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.