Skip to content

Blog

Sometimes a Mutex Is Right

A blocking channel that is not trying to be fast, only correct, with timeouts and a shutdown that actually drains.

After a chapter of lock-free structures that avoid mutexes at all costs, here is the honest counterweight: a queue that reaches straight for one. The twenty-fourth familiar is not chasing throughput. It is chasing the two things fast queues are bad at, waiting with a timeout and shutting down without losing or hanging on the items still in flight, and for those, a mutex and two condition variables are simply the right tool.

Built to Disappear

An atomic shared_ptr that becomes a one-line alias the moment the standard library grows its own.

You want to atomically swap a shared_ptr, publish a new version of some shared state without a lock of your own, and read it safely from other threads. C++20 finally standardized that, but not every compiler shipped it. The twenty-third familiar fills the gap where it is missing and, more interestingly, is written to delete itself the moment the standard library grows the feature, so the dependency has a built-in expiry date.

Many Ways to Be Similar

A family of string-distance metrics behind one interface, because there is no single answer to 'how close.'

There is no such thing as the string-similarity metric. A typo wants edit distance; a name wants prefix weighting; a jumbled word wants shared letters; a misspelling wants sound. The twenty-second familiar admits this and ships a whole family, edit distance, Jaro-Winkler, Jaccard, Dice, and more, all behind one interface, so choosing the right notion of close is a matter of picking a class.

Smith and Schmidt

Matching names by how they sound, not how they are spelled.

Smith and Schmidt are the same name, spelled two ways. Any system that matches on exact spelling will never connect them, which is a problem if you are searching for people, whose names arrive spelled every possible way. The twenty-first familiar reads a word the way it is said, not written, and emits two keys so that a name and its foreign cousin finally meet.

The Earth Is Not a Ball

Turning latitude and longitude into vectors you can do geometry on, on an Earth that is lumpier than a sphere.

Latitude and longitude are angles on a curved surface, and you cannot take the dot product of two angles. To do real geometry on the Earth, measure an angle between two cities, feed a region to a spatial index, you first turn each point into a vector in space. The twentieth familiar does that conversion, honestly, across an Earth that is neither round nor drawn on a single map.