Open Source Tech
Go sync.Cond, the Most Overlooked Sync Mechanism
In Go, sync.Cond is a synchronization primitive, though it’s not as commonly used as its siblings like sync.Mutex or sync.WaitGroup. That said, as a Go engineer, you don’t really want to find yourself reading through code that uses sync.Cond and not have a clue what’s going on.
The Rise of Open Source Time Series Databases
Time series databases are essential tools in any software engineer’s toolbelt. Their development has been shaped by user needs and countless open source contributors, leading to the healthy ecosystem of options we see today. In this article, you’ll see how time series databases came about, and why so many are open source.
Go sync.WaitGroup and The Alignment Problem
When we’re spinning off many goroutines to do their thing, we want to keep track of them so that the main goroutine doesn’t just finish up and exit before everyone else is done. That’s where the WaitGroup comes in. Each time one of our goroutines wraps up its task, it lets the WaitGroup know.
Slices in Go: Grow Big or Go Home
Slices are way more flexible than arrays since they’re basically a layer on top of an array. They can resize dynamically, and you can use append()
to add more elements.
Go sync.Pool and the Mechanics Behind It
Instead of just throwing these objects after each use, which would only give the garbage collector more work, we stash them in a pool (sync.Pool
). The next time we need something similar, we just grab it from the pool instead of making a new one from scratch.
Go Maps Explained: How Key-Value Pairs Are Actually Stored
Map is a built-in type that acts as a key-value storage. Unlike arrays where you’re stuck with keys as increasing indices like 0, 1, 2, and so on, with maps, the key can be any comparable type.
Go sync.Mutex: Normal and Starvation Mode
Mutex in Go has two main flows: Lock and Unlock and 2 modes: Normal and Starvation Mode. The state field of mutex is a 32-bit integer that represents the current state, it’s divided into multiple bits that encode various pieces of information about the mutex.
How Go Arrays Work and Get Tricky with For-Range
As always, we’ll start with the basics and then dig a bit deeper. Don’t worry, Go arrays get pretty interesting when you look at them from different angles. Arrays in Go are a lot like those in other programming languages. They’ve got a fixed size and store elements of the same type in contiguous memory locations.
Golang Defer: From Basic To Traps
The defer statement actually has 3 types: open-coded defer, heap-allocated defer, and stack-allocated. Each one has different performance and different scenarios where they’re best used, which is good to know if you want to optimize performance.
Vendoring, or go mod vendor: What Is It?
Vendoring is a different strategy as it keeps a copy of all your project’s dependencies directly within the project’s directory, rather than relying on an external cache.