Skip to content

Commit 6b57c93

Browse files
Changes for GOMAXPROCS
1 parent 4f34ee2 commit 6b57c93

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎chapter6/listing01/listing01.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ package main
44

55
import (
66
"fmt"
7+
"runtime"
78
"sync"
89
)
910

1011
// main is the entry point for all Go programs.
1112
func main() {
13+
// Allocate 1 logical processor for the scheduler to use.
14+
runtime.GOMAXPROCS(1)
15+
1216
// wg is used to wait for the program to finish.
1317
// Add a count of two, one for each goroutine.
1418
var wg sync.WaitGroup

‎chapter6/listing04/listing04.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package main
44

55
import (
66
"fmt"
7+
"runtime"
78
"sync"
89
)
910

@@ -12,6 +13,9 @@ var wg sync.WaitGroup
1213

1314
// main is the entry point for all Go programs.
1415
func main() {
16+
// Allocate 1 logical processors for the scheduler to use.
17+
runtime.GOMAXPROCS(1)
18+
1519
// Add a count of two, one for each goroutine.
1620
wg.Add(2)
1721

‎chapter6/listing07/listing07.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010

1111
// main is the entry point for all Go programs.
1212
func main() {
13+
// Allocate two logical processors for the scheduler to use.
14+
runtime.GOMAXPROCS(2)
15+
1316
// wg is used to wait for the program to finish.
1417
// Add a count of two, one for each goroutine.
1518
var wg sync.WaitGroup
1619
wg.Add(2)
1720

18-
// Allocate two logical processors for the scheduler to use.
19-
runtime.GOMAXPROCS(2)
20-
2121
fmt.Println("Start Goroutines")
2222

2323
// Declare an anonymous function and create a goroutine.

0 commit comments

Comments
 (0)