semaphore.pm

来自「mysql+ha. 实现高可用性 http://code.google.com」· PM 代码 · 共 32 行

PM
32
字号
package Thread::Semaphore;use threads::shared;sub new {    my $class = shift;    my $val : shared = @_ ? shift : 1;    # Workaround because of memory leak    return bless \\$val, $class;}sub down {    my $s = shift;    # Double dereferencing    $s = $$s;    lock($$s);    my $inc = @_ ? shift : 1;    cond_wait $$s until $$s >= $inc;    $$s -= $inc;}sub up {    my $s = shift;    # Double dereferencing    $s = $$s;    lock($$s);    my $inc = @_ ? shift : 1;    ($$s += $inc) > 0 and cond_broadcast $$s;}1;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?