Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: Faster locking

by bbs2web (Acolyte)
on Apr 04, 2017 at 08:38 UTC ( [id://1186970]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Faster locking
in thread Faster locking

Okay, so it works as expected:

Test code:

#!/usr/bin/perl use strict; use warnings; use Fcntl qw(:flock); open our $lockfile, '<', $0 || die $!; if ( (1 == 1) || (!flock $lockfile, LOCK_EX | LOCK_NB) ) { print "in loop\n"; sleep 30; if (flock $lockfile, LOCK_EX | LOCK_NB) { print "locked\n"; } else { print "not locked\n"; } sleep 30; }

First instance:

in loop locked

Second instance:

in loop not locked

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1186970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found