You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: day07-goroutines-channels-1/goroutines.go
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,14 @@ import (
6
6
"time"
7
7
)
8
8
9
+
funcinit() {
10
+
11
+
runtime.GOMAXPROCS(runtime.NumCPU())
12
+
}
9
13
10
14
funcsayMyName(namestring){
11
15
fori:=0; i<5; i++ {
12
-
runtime.Gosched()
16
+
runtime.Gosched()//Gosched yields the processor, allowing other goroutines to run. It does not suspend the current goroutine, so execution resumes automatically.
13
17
fmt.Println("Oh na na what's my name? ", name)
14
18
time.Sleep(100*time.Millisecond) //doing some fake work here... please wait ZzzZzzZzzz
15
19
}
@@ -18,7 +22,6 @@ func sayMyName(name string){
18
22
19
23
funcmain() {
20
24
21
-
runtime.GOMAXPROCS(runtime.NumCPU())
22
25
23
26
fmt.Println("You've got", runtime.NumCPU() , " CPU cores yo!")
24
27
@@ -32,7 +35,7 @@ func main() {
32
35
33
36
gosayMyName("bbbbbbbbbb")
34
37
35
-
varinputstring
36
-
fmt.Scanln(&input)
38
+
// var input string
39
+
// fmt.Scanln(&input)
37
40
fmt.Println("ok dude! the show is over, go home and eat a potato")
0 commit comments