Skip to content

Commit 2f02bfd

Browse files
committed
Fix compile errors and add the test result from Macbook Pro (Mid-2014)
1 parent 6df2828 commit 2f02bfd

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

concurrency/go/hello1/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
47

58
func 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
}

concurrency/go/hello2/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
47

58
func 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
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

concurrency/ruby/hello1.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
end
1515

1616
# wait for all thread finishes
17-
threads.each &:joni
17+
threads.each &:join

concurrency/ruby/hello2.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
count = 0
2+
threads = []
23

34
1000.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
@@ -13,6 +14,4 @@
1314
end
1415

1516
# wait for all thread finishes
16-
while count < 1000 do
17-
# do nothing
18-
end
17+
threads.each &:join

0 commit comments

Comments
 (0)