HNHacker News
TopNewBestAskShowJobs

j_seigh

43 karma · joined May 16, 2025

submissionscomments
j_seigh··on Wait-Free Hazard Pointers Using Std Atomics
A few ways to do wait-free hazard pointers, some portable, semi-portable, or not so much in this an subsequent blog posts. It's pretty high level, I'm assuming one knows how asymetric memory barriers and hazard pointers without the store/load memory barrier work.

Wait-free is interesting more from an academic point of view in that you can use hazard pointers to implement wait-free algorithms and still claim they are wait-free.

While one of them is 50% faster than lock-free hazard pointers, probably due to not having a conditional branch, the latter is pretty fast already.

j_seigh··on Atomics and Concurrency
You used quotes so I can't tell if you think it's a real problem or just a self inflicted one because the warning that finalizers aren't guaranteed to run was ignored.

If the finalizer was for an object that is just memory, it's not a problem. The GC has decided it doesn't need to recover the memory used by that object just yet. I've seen this with heaps defined to be large enough to handle a memory spike. When the spikes stop happening, a lot of stuff in the old gen pool just stays there. At one point I was looking at 50GB heap dumps looking for memory leaks.

It is a problem when the object has non memory resources like a socket descriptor. You can run out of descriptors. So not relying on GC and using try with resource is a good idea.

j_seigh··on Read-Copy-Update (RCU)
I've done implementations of most of these (qsbr, ebr, atomic reference counting, hazard pointers w/o the store/load memory barrier (you're welcome btw), etc...) and have a pretty good idea of how they work and how to use them. I think there should be more articles on how to use them properly. It's not obvious and can be a bit tricky if you don't have experience in this area.

A simple example would be how to implement a simple linked list that can be traversed safely under concurrent modifications.

j_seigh··on Millions of bees escape, start stinging after crash
Could have been worse https://www.nytimes.com/1994/08/05/nyregion/the-terror-of-th... It was really hot and traffic was backed up and at a standstill, so sitting in a car with windows rolled up for hours could not have been pleasant. I had spotted the backup beforehand and avoided it fortunately.
j_seigh··on Atomics and Concurrency
Performance from using atomics in reference counting is going to degrade quite a bit under heavy usage due to cache contention. If you are in that situation, you should be looking at something else like RCU or hazard Pointers.
j_seigh··on Distributed Time Keeping
Esper (used for streaming correlation and pattern matching) has time order windows. Basically within a specified time window size, it will reorder events according to their timestamps if they are not too far out of order. For real time streaming, that will delay event processing by what the window size is. For something like Kafka that wouldn't be a problem so much.
j_seigh··on Memory Consistency Models: A Tutorial
AFAIK, the relaxed memory models are mostly from processors using pipelined execution and out of order execution. Cache has little to do with it as most modern processors have transparent cache, meaning you can't tell it there except for performance effects. Differences in memory accesses due to cache state might exacerbate some race conditions but those race conditions would still be there, cache or no cache.
j_seigh··on Lock-Free Rust: How to Build a Rollercoaster While It's on Fire
I did a lock-free ABA-free bounded queue in c++ kind of an exercise. I work mostly with deferred reclamation schemes (e.g. refcounting, quiescent state based reclamation, and epoch based reclamation). A queue requiring deferred reclamation, like the Michael-Scott lock-free queue is going to perform terribly so you go with an array based ring buffer. It uses a double wide CAS to do the insert for the enqueue and a regular CAS to update the tail. Dequeue is just a regular CAS to update the head. That runs about 57 nsecs on my 10th gen i5 for single producer and consumer.

A lock-free queue by itself isn't very useful. You need a polling strategy that doesn't involve a busy loop. If you use mutexes and condvars, you've basically turned it into a lock based queue. Eventcounts work much better.

If I run more threads than CPUs and enough work so I get time slice ends, I get about 1160 nsecs avg enq/deq for mutex version, and about 146 nsecs for eventcount version.

Timings will vary based on how man threads you use and cpu affinity that takes your hw thread/core/cache layout into consideration. I have gen 13 i5 that runs this slower than my gen 10 i5 because of the former's efficiency cores even though it is supposedly faster.

And yes, a queue is a poster child for cache contention problems, une enfant terrible. I tried a back off strategy at one point but it didn't help any.

← PreviousPage 2 of 2