
Spinlocks vs Mutexes: When Spinning Wins
A spinlock burns a core while it waits and a mutex sleeps. Compare their costs, write a correct C11 spinlock, and see when user-space spinning beats a mutex.
Allocators, cache-friendly data layout, profiling with perf, VTune and Instruments, benchmarking that means something, and memory safety without losing speed.

A spinlock burns a core while it waits and a mutex sleeps. Compare their costs, write a correct C11 spinlock, and see when user-space spinning beats a mutex.

Wrap per-thread atomics in crossbeam_utils::CachePadded to keep each on its own cache line in Rust, with size checks, scoped threads and a repr(align) option.

Use C++17's std::hardware_destructive_interference_size to pad against false sharing, with the feature-test macro, the GCC warning and a safe fallback constant.

Fix false sharing in C++17 by giving each thread's data its own cache line with alignas(64), explicit padding, static_assert checks and aligned heap allocation.

Amdahl's law caps parallel speedup at one over the serial fraction. Work the numbers in C and see why a 95 percent parallel program tops out at 20 times.

False sharing makes threads that write different variables slow each other down because they share a cache line. See it in a four-thread C counter.

Control hyperfine 1.19 with --warmup, --prepare, --setup, --cleanup and --parameter-scan to measure cold and warm runs and sweep threads or compilers.

Build a small, correct C benchmark harness with clock_gettime(CLOCK_MONOTONIC), a compiler barrier, warm-up, many repetitions and a median in eighty lines.

Set up Criterion 0.5 in Rust 1.83, write a bench_function with black_box, run cargo bench and read the time estimate, outliers and change detection.

Pick the right OpenMP loop schedule by looking at how iteration cost varies, with deterministic examples of static, dynamic, guided and runtime scheduling.

Build Google Benchmark 1.9, write a first BM_ function with the state loop, read the Time, CPU and Iterations columns, and avoid beginner traps.

Benchmark any command with hyperfine 1.19: it runs warm-ups and many repetitions, reports mean, spread and range, and compares commands against each other.
We send one email when a new post is published. No spam.