File tree Expand file tree Collapse file tree 5 files changed +56
-9
lines changed
Expand file tree Collapse file tree 5 files changed +56
-9
lines changed Original file line number Diff line number Diff line change 11package main
22
3- import "fmt"
3+ import (
4+ "fmt"
5+ "runtime"
6+ )
47
58func main () {
9+ runtime .GOMAXPROCS (0 )
10+
611 quitSignal := make (chan int )
712
813 greetings := "hello"
914 for i := 0 ; i < 1000 ; i ++ {
1015 go func (i int , signal chan int ) {
11- fmt .Printf ("%s from goroutine number %d\n " , greetings , i )
16+ fmt .Printf ("%s from goroutine number %d\n " , greetings , i )
1217 signal <- 1
1318 }(i , quitSignal )
1419 }
Original file line number Diff line number Diff line change 11package main
22
3- import "fmt"
3+ import (
4+ "fmt"
5+ "runtime"
6+ )
47
58func main () {
9+ runtime .GOMAXPROCS (0 )
10+
611 quitSignal := make (chan int )
712
813 greetings := "hello"
914 for i := 0 ; i < 1000 ; i ++ {
1015 go func (i int , signal chan int ) {
11- fmt .Printf ("%s from goroutine number %d\n " , greetings , i )
16+ fmt .Printf ("%s from goroutine number %d\n " , greetings , i )
1217 signal <- 1
1318 }(i , quitSignal )
1419 }
Original file line number Diff line number Diff line change 1+ ## Go
2+ ### hello1:
3+
4+ real 0m0.008s
5+ user 0m0.003s
6+ sys 0m0.004s
7+
8+ ### hello2:
9+
10+ real 0m0.007s
11+ user 0m0.003s
12+ sys 0m0.004s
13+
14+ ## Rust
15+ ### hello1
16+
17+ real 0m0.010s
18+ user 0m0.002s
19+ sys 0m0.005s
20+
21+ ### hello2
22+
23+ real 0m0.036s
24+ user 0m0.054s
25+ sys 0m0.092s
26+
27+ ## Ruby
28+ ### hello1
29+
30+ real 0m0.029s
31+ user 0m0.021s
32+ sys 0m0.007s
33+
34+ ### hello2
35+
36+ real 0m0.206s
37+ user 0m0.143s
38+ sys 0m0.085s
Original file line number Diff line number Diff line change 1414end
1515
1616# wait for all thread finishes
17- threads . each &:joni
17+ threads . each &:join
Original file line number Diff line number Diff line change 11count = 0
2+ threads = [ ]
23
341000 . times do |i |
4- Thread . new do
5+ threads << Thread . new do
56 greeting_message = "Hello"
67
78 # This is weird in Ruby but it's closer to the println! macro
1314end
1415
1516# wait for all thread finishes
16- while count < 1000 do
17- # do nothing
18- end
17+ threads . each &:join
You can’t perform that action at this time.
0 commit comments