Skip to content

Commit 9f451d9

Browse files
Removed mutex. Race detector did not spot anything.
1 parent 48efe2c commit 9f451d9

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

‎chapter2/sample/search/search.go‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@ import (
55
"sync"
66
)
77

8-
var (
9-
// Used to synchronize access to the matchers map.
10-
lock sync.Mutex
11-
12-
// A map of registered matchers for searching.
13-
matchers map[string]Matcher = make(map[string]Matcher)
14-
)
8+
// A map of registered matchers for searching.
9+
var matchers map[string]Matcher = make(map[string]Matcher)
1510

1611
// Register is called to register a matcher for use
1712
// by the program.
1813
func Register(feedType string, matcher Matcher) {
19-
// Enter a critical section and schedule the unlock.
20-
lock.Lock()
21-
defer lock.Unlock()
22-
2314
// Assign the matcher to the specified key.
2415
log.Println("Register", feedType)
2516
matchers[feedType] = matcher
@@ -45,14 +36,14 @@ func Run(searchTerm string) {
4536

4637
// Launch a goroutine for each feed to find the results.
4738
for _, feed := range feeds {
48-
// Create a matcher for the search.
39+
// Retrieve a matcher for the search.
4940
matcher, ok := matchers[feed.Type]
5041
if !ok {
5142
matcher = matchers["default"]
5243
}
5344

5445
// Make a copy of the value to give each goroutine
55-
// there own copy of the value.
46+
// their own copy.
5647
find := feed
5748

5849
// Launch the goroutine to perform the search.

0 commit comments

Comments
 (0)