Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

OpenMP or PThreads?

Name: Anonymous 2012-07-13 1:32

OpenMP or PThreads?

Name: Anonymous 2012-07-13 9:45

Go (golang.org) has amazing multithreading support. Give Go a look if you get a chance, it's a beautiful language.


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)
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List