Help us understand the problem. What is going on with this article?

ズンドコキヨシGolang並列版

More than 3 years have passed since last update.

元ネタ

http://qiita.com/shunsugai@github/items/971a15461de29563bf90

Go並列版

途中経過の出力不可能ですが

package main

import (
    "fmt"
    "math/rand"
    "runtime"
    "sync"
    "time"
)

// Zundoko is ズンドコ配列
var Zundoko = [2]string{"ズン", "ドコ"}

func main() {
    cpus := runtime.NumCPU()
    runtime.GOMAXPROCS(cpus)
    kiyoshiCh := make(chan bool, 1)
    var m sync.Mutex
    for i := 0; i < cpus; i++ {
        go zndk(kiyoshiCh, &m)
    }

    <-kiyoshiCh
    close(kiyoshiCh)
    fmt.Println("キ・ヨ・シ!")
}

func zndk(kiyoshiCh chan bool, m *sync.Mutex) {
    zdk := make([]string, 5)
    for {
        for i := 0; i < 5; i++ {
            zdk[i] = getZndk(m)
        }
        if zdk[0] == "ズン" && zdk[1] == "ズン" && zdk[2] == "ズン" && zdk[3] == "ズン" && zdk[4] == "ドコ" {
            for _, s := range zdk {
                fmt.Println(s)
            }
            kiyoshiCh <- true
            break
        }
    }
}

func getZndk(m *sync.Mutex) string {
    m.Lock()
    defer m.Unlock()
    rand.Seed(time.Now().UnixNano())
    return Zundoko[rand.Intn(2)]
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした