Skip to content

Instantly share code, notes, and snippets.

@yakmoose
Created March 16, 2015 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakmoose/b1640e289f18d8c42a37 to your computer and use it in GitHub Desktop.
Save yakmoose/b1640e289f18d8c42a37 to your computer and use it in GitHub Desktop.
simple sem
Sem = function (initial, pFunc, vFunc) {
this.pFunc = pFunc || function () { };
this.vFunc = vFunc || function () { };
this.set(initial);
};
Sem.prototype.set = function(v){
this.sem = v
if (v > 0){
this.vFunc();
}
if (v <= 0){
this.pFunc();
}
}
Sem.prototype.p = function () {
this.sem--;
if (this.sem <= 0) {
this.pFunc();
}
};
Sem.prototype.v = function () {
this.sem++;
if (this.sem > 0) {
this.vFunc();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment