Skip to content

cla/sem - Semaphore control

This namespace contains functions that allow the developer to use semaphores in their code.


Takes a semaphore to execute the code block passed as an argument.

var sem = require("cla/sem");
var log = require("cla/log");
var util = require("cla/util");
var ret = sem.take('abc', function(){
    util.sleep(0.05); 'here we are' );
    return 123;
print( ret );

Take consumes 1 semaphore slot. This typically means that no other process can take the same semaphore, unless an administrator has increased the semaphore slot availability, in which case more process can be taken.

The semaphore slot is released at the end.


Purges all semaphores that are blocked for the given key, releasing all processes that are waiting for a given semaphore simultaneously.

This function is useful to unlock system resources that were blocked and were not released.