This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extract a core module like this | |
var http = require('http); | |
// extract a user defined module like this | |
var something = require('./folder1/folder2/folder3/something.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof Object.create !== 'function') { | |
Object.create = function (o) { | |
var F = function () {}; | |
F.prototype = o; | |
return new F(); | |
}; | |
var otherPerson = Object.create(person); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// take order for table 1 and move on... | |
orderNonBlocking(['Coke', 'Iced Tea'], function(drinks){ | |
return serveOrder(drinks); | |
}); | |
// take order for table 2 and move on... | |
orderNonBlocking(['Beer', 'Whiskey'], function(drinks){ | |
return serveOrder(drinks); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// take order for table 1 and wait... | |
var order1 = orderBlocking(['Coke', 'Iced Tea']); | |
// once order is ready, take order back to table. | |
serveOrder(order1); | |
// once order is delivered, move on to another table. | |
// take order for table 2 and wait... | |
var order2 = orderBlocking(['Coke', 'Water']); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wait(mutex) | |
//safely use shared resource | |
release(mutex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wait(mutex) | |
//safely use shared resource | |
release(mutex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wait(S) { | |
if(S <= 0) | |
/* wait */ | |
S--; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signal(S) { | |
S++; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
release() { | |
available = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acquire() { | |
while (!available) | |
/* schedule another process */ | |
available = false | |
} | |
do { | |
acquire lock | |
critical section | |
release lock | |
remainder section |