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
package main | |
import fmt "fmt" | |
import runtime "runtime" | |
func parallel(f ... func()) { | |
c := make(chan int, len(f)) | |
for i := 0; i < len(f); i++ { | |
f := f[i] | |
go func() { |
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
// Hamming sequence http://oeis.org/A051037 | |
// multipliers for subsequences and corresponding next element | |
var index = [ { mul: 2, next: 0 }, { mul: 3, next: 0 }, { mul: 5, next: 0 } ]; | |
var queue = []; | |
function next() { | |
// special case for the seed of the sequence | |
if (queue.length == 0) { |
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
// Dining Philosophers problem | |
function Phil(me, left, right) { | |
var run = function() { | |
sequential([ | |
500, // pause | |
function() { console.log(me + ' sits'); }, | |
left, // channel | |
function() { console.log(me + ' picked left fork'); }, | |
500, |
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
// Problem from Concurrent Programming course exercises | |
// Two kinds of processes Man and Woman pair off with the help of a Matcher | |
function random(max) { | |
return Math.floor(Math.random()*max); | |
} | |
function Man(name) { | |
setTimeout(function run() { | |
matcher.Man(name, function(pair) { |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.