Files
llgo/cl/_testlibc/atomic/in.go

26 lines
449 B
Go
Raw Normal View History

2024-06-16 03:49:09 +08:00
package main
import (
"github.com/goplus/llgo/c"
2024-06-16 16:35:46 +08:00
"github.com/goplus/llgo/c/sync/atomic"
2024-06-16 03:49:09 +08:00
)
func main() {
2024-06-16 16:35:46 +08:00
var v int64
2024-06-16 03:49:09 +08:00
2024-06-16 16:35:46 +08:00
atomic.Store(&v, 100)
2024-06-16 16:39:55 +08:00
c.Printf(c.Str("store: %ld\n"), atomic.Load(&v))
2024-06-16 03:49:09 +08:00
2024-06-16 16:35:46 +08:00
atomic.Add(&v, 1)
c.Printf(c.Str("v: %ld\n"), v)
2024-06-16 15:20:29 +08:00
2024-06-16 16:35:46 +08:00
atomic.CompareAndExchange(&v, 100, 102)
c.Printf(c.Str("v: %ld\n"), v)
atomic.CompareAndExchange(&v, 101, 102)
c.Printf(c.Str("v: %ld\n"), v)
atomic.Sub(&v, 1)
c.Printf(c.Str("v: %ld\n"), v)
2024-06-16 03:49:09 +08:00
}