Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions A-mutex.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ type counter struct {
val int
}

func (c *counter) Add(x int) {
func (c *counter) Add(int) {
c.val++
}

func (c *counter) Value() (x int) {
func (c *counter) Value() (int) {
return c.val
}
```
Expand Down Expand Up @@ -107,13 +107,13 @@ type counter struct {
val int
}

func (c *counter) Add(x int) {
func (c *counter) Add(int) {
c.Lock()
c.val++
c.Unlock()
}

func (c *counter) Value() (x int) {
func (c *counter) Value() (int) {
return c.val
}
```
Expand All @@ -133,11 +133,11 @@ Coba jalankan program, dan lihat hasilnya.
Pada contoh di atas, mutex diterapkan dengan cara di-embed ke objek yang memerlukan proses lock-unlock, menjadikan variabel mutex tersebut adalah eksklusif untuk objek tersebut saja. Cara ini merupakan cara yang dianjurkan. Meskipun demikian, mutex tetap bisa digunakan dengan cara tanpa ditempelkan ke objek yang memerlukan lock-unlock. Contohnya bisa dilihat di bawah ini.

```go
func (c *counter) Add(x int) {
func (c *counter) Add(int) {
c.val++
}

func (c *counter) Value() (x int) {
func (c *counter) Value() (int) {
return c.val
}

Expand Down