LedgerMath
← All benchmarksHow mutex works

Lock and unlock a mutex

mutex · compared across machine types · 35 Series on 8 machine types · AWS us-east-2

CPU
Section
Idle
Placement
Threads
Order
CompareMachineVariantP50P99Unit costRuns
c8a.2xlarge10.20 ns—$0.00000122 /1M ops89
c8i.2xlarge13.64 ns—$0.00000142 /1M ops89
m5.large17.51 ns—$0.000000467 /1M ops91
c8g.2xlarge17.93 ns—$0.00000158 /1M ops4
c6i.8xlarge18.38 ns—$0.00000533 /1M ops89
i4i.2xlarge18.39 ns—$0.0000035 /1M ops89
m6id.2xlarge18.39 ns—$0.00000242 /1M ops1
i4g.2xlarge22.42 ns—$0.00000383 /1M ops4
Compared:m5.largec8g.2xlargec8i.2xlarge

Run-to-run spread

time per critical section across counted Runs

Over time

newest counted Runs, time per critical section

(one request each to the data API)

What this measures

What a critical section under a pthread mutex costs: uncontended on one thread, and with two threads contending for it on two physical cores or on the two hardware threads of one core.

What it does not measure

  • With two threads, the figure is not the time for the lock to pass from one core to the other.
  • With threads 1, one_cpu and idle_threads 0, the figure is true only of a process that has only ever had one thread, where glibc skips the atomic instructions. A program that has started a thread pays for them, as the same set with idle_threads 1 does.
  • With threads 1, one_cpu and idle_threads 1, on c6i.8xlarge and i4i.2xlarge, the Runs counted on 2026-11-25 usually sat at one of two levels from boot to boot, about 30% apart, with one Run between them, and in the Runs examined no recorded fact told the levels apart.

The whole method, on its page →

c8i.2xlarge · 1 line · +1 idle · one cpu · 1 thread

Beat this hot path on GitHub ↗