Skip to content

Commit fe0c01a

Browse files
committed
day11 in advance Mutex
1 parent a5ce72b commit fe0c01a

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

day10-buffered-async-channels-4/channel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828

2929
failedMessage := FailedMessage{
3030
ErrorMessage: "Interrupted by the black riders",
31-
OriginalMessage: Message{},
31+
OriginalMessage: msg,
3232
}
3333

3434
msgCh <- msg

day11-concurrency-models-5/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go over all the different concurrency models and concepts with goroutines and channels

day11-concurrency-models-5/events.go

Whitespace-only changes.

day11-concurrency-models-5/mutex.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
"sync"
7+
)
8+
9+
func main() {
10+
11+
runtime.GOMAXPROCS(4)
12+
mutex := new(sync.Mutex)
13+
14+
for i := 1; i < 10; i++ {
15+
//fmt.Println(i)
16+
for j := 1; j < 10; j++ {
17+
mutex.Lock()
18+
go func() {
19+
fmt.Printf("%d %d\n", i, j)
20+
mutex.Unlock()
21+
22+
}()
23+
}
24+
}
25+
26+
}
27+
28+
//Not sure why it prints the value 10 even with the use of Mutex

0 commit comments

Comments
 (0)