Rohit Sachdeva

@rsachdeva
1 Followers
7 Following
15 Posts
#Golang #Go #Ziglang #Zig #Rustlang #Rust Senior Backend & Systems Software Engineer https://github.com/rsachdeva
@ck Always benchmark, but for writer starvation: "https://pkg.go.dev/sync#RWMutex If any goroutine calls RWMutex.Lock while the lock is already held by one or more readers, concurrent calls to RWMutex.RLock will block until the writer has acquired (and released) the lock, to ensure that the lock eventually
becomes available to the writer. Note that this prohibits recursive read-locking."
sync package - sync - Go Packages

Package sync provides basic synchronization primitives such as mutual exclusion locks.

Lock() in sync.Mutex / sync.RWMutex vs RLock() in sync.RWMutex:
Lock() — blocks readers AND writers
RLock() — blocks writers only, does NOT block other readers

Use RWMutex RLock() when reads >> writes.
#golang #concurrency

sync.Once's .Do and sync.OnceFunc both take func() — no return.
So the result has to live somewhere: a separate struct field you write to as a side effect.

sync.OnceValue takes func() T — the return value IS the cache. No extra field.

#golang #concurrency

time.After(d): Concurrency tool. Sets up a background timer and returns a channel.

t.After(u): Date/time method. Instant boolean comparison to check if timestamp t occurs after timestamp u.

#Golang time package

Go proverb: “errors are values” means “errors are values that implement the `error` interface.”

#Golang

Release notes are up!

I wish it went without saying, but these notes are completely written by hand.

https://ziglang.org/download/0.16.0/release-notes.html

0.16.0 Release Notes ⚡ The Zig Programming Language

Go's time package has two sides:
date/time handling
Timer-based concurrency tools:

time.NewTimer(d)
timer.Stop()
timer.Reset(d)
time.After(d)
time.AfterFunc(d, f)
time.NewTicker(d)
ticker.Stop()
time.Tick(d)

#golang #concurrency

Go goroutine stack dumps show a bracketed state like [chan send] or [chan receive]: that means blocked. The full list lives in src/runtime/runtime2.go as waitReason constants. Not documented anywhere else. #golang https://github.com/golang/go/blob/fa238516b782bd1f233e85b719b7ab90889a5634/src/runtime/runtime2.go#L1221
go/src/runtime/runtime2.go at fa238516b782bd1f233e85b719b7ab90889a5634 · golang/go

The Go programming language. Contribute to golang/go development by creating an account on GitHub.

GitHub
Check out the official list of Go replacements: pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize
From Go 1.26+, `go fix` helps you with each of these replacements automatically! #golang
@mitchellh Nice! Now with search 🔎