Standard library / sync/atomic
atomic.StoreInt64()
Atomically replace the current value. Other shared data needs its own synchronization protocol. Raw pointer APIs require correctly aligned storage; prefer the corresponding typed atomic in new code. Expected stdout: '15\n'.
Formal Syntax & Structure
go syntaxgo
func StoreInt64(addr *int64, val int64)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| addr | *int64 | Pointer to the shared variable; satisfy architecture alignment requirements and use atomic access consistently. |
| val | int64 | Value to store; context values should be request-scoped. |
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { x := new(int64) atomic.StoreInt64(x, 12) atomic.StoreInt64(x, 15) fmt.Println(atomic.LoadInt64(x))}