Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/d3m3vilurr/aumutex

Named mutex terminated due to the process end of automatic
https://github.com/d3m3vilurr/aumutex

Last synced: 20 days ago
JSON representation

Named mutex terminated due to the process end of automatic

Awesome Lists containing this project

README

        

aumutex
=======

Named mutex terminated due to the process end of automatic

## Examples

```javascript
// from test.js
var cluster = require('cluster');
var sleep = require('sleep');
var aumutex = require('./aumutex');

var mutex_name = '/var/tmp/mymutex';

if (cluster.isMaster) {

cluster.fork();
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
sleep.sleep(2);

var master_mutex = aumutex.create(mutex_name);
console.info('[MASTER] create');

console.info('[MASTER] wait');
aumutex.enter(master_mutex);
console.info('[MASTER] enter');

console.info('[MASTER] close');
aumutex.close(master_mutex);

master_mutex = aumutex.create(mutex_name);
console.info('[MASTER] re-create');

console.info('[MASTER] wait');
sleep.sleep(2);
aumutex.enter(master_mutex);
console.info('[MASTER] re-enter');

aumutex.close(master_mutex);
console.info('[MASTER] process.exit()');
process.exit();

} else {

var worker_mutex = aumutex.create(mutex_name);
console.info('[WORKER] create');

aumutex.enter(worker_mutex);
console.info('[WORKER] enter');

sleep.sleep(2);
console.info('[WORKER] leave');
aumutex.leave(worker_mutex);

sleep.sleep(2);
console.info('[WORKER] wait');
aumutex.enter(worker_mutex);
console.info('[WORKER] re-enter');
sleep.sleep(2);

console.info('[WORKER] process.exit()');
process.exit();
}

--- result ----
[WORKER] create
[WORKER] enter
[MASTER] create
[MASTER] wait
[WORKER] leave
[MASTER] enter
[MASTER] close
[MASTER] re-create
[MASTER] wait
[WORKER] wait
[WORKER] re-enter
[WORKER] process.exit()
[MASTER] re-enter
[MASTER] process.exit()
```