1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

並列・並行処理(簡単な実現方法を調べる)

Last updated at Posted at 2020-05-27

こんにちは。
並列・並行処理の簡単な実現方法を調べてみました。他にもあれば調べたいです。

Unix

$ seq 10 | xargs -n 1 -P 8 exec_something

Go

maxProc := 8
limiter := make(chan struct{}, maxProc)
items := []int{1,2,3,4,5,6,7,8,9,10}
var wg sync.WaitGroup
for _, item := range items {
    wg.Add(1)
    go func(i int) {
    	limiter <- struct{}{}
        defer wg.Done()
        exec_something(i)
        <-limiter
    }(item)
}
wg.Wait()
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?