Исходники и презентации
This commit is contained in:
16
lessons/sync_primitives/action_during_actions/main.go
Normal file
16
lessons/sync_primitives/action_during_actions/main.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
// Need to show solution
|
||||
|
||||
type Data struct {
|
||||
count atomic.Int32
|
||||
}
|
||||
|
||||
func (d *Data) Process() {
|
||||
d.count.Add(1)
|
||||
if d.count.CompareAndSwap(100, 0) {
|
||||
// do something...
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user