Name: Anonymous 2012-07-13 1:32
OpenMP or PThreads?
package main
import (
"fmt"
"math/rand"
"time"
)
const (
Threads = 10
)
func uselessFunction(c chan int) {
c <- rand.Int() % 100
}
func main() {
//A Channel is a way to send messages across threads
c := make(chan int)
rand.Seed(time.Now().Unix())
//The go keyword spawns a given function in a new thread
for i := 0; i < Threads; i++ {
go uselessFunction(c)
}
//The <- operator means recieve, reading from a channel blocks
//until data is sent.
for i := 0; i < Threads; i++ {
fmt.Println(<-c)
}
}