samedi 24 janvier 2015

basic logic of lock - mutual exclusion

I'm struggling with the logic of lock for mutual exclusion; Here Im checking if the key is taken or not, if not we take it and when done release it; but could you please help me how I can have a loop to check the key until it becomes available?



rdb.setnx(lockkey, 'taken', function (err, lockvalue) {
if (err) {
console.error(err);
} else if (lockvalue == 1) {
// You have the lock; process it
//Release the key when you are done:
rdb.del(lockkey);
} else if (lockvalue == 0) {
// Key is taken by someone else; so how can I have a loop to check until key is available to take?
}
});


Your help is appreciated :-)


Aucun commentaire:

Enregistrer un commentaire