C8 Computer organization · Practice
Atomic instructions and locks
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
0 solved
0 in a row
0 of 8 kinds solid
Check
Two threads each increment a shared counter (starting at 0) 3 times using atomic amoadd.w. What is the final value?
Check
2 cores hammer one shared atomic counter. Every increment needs the cache line, which takes 100 ns to move between cores. About how many million increments per second happen in total?
Check
A contended spinlock takes 100 ns to acquire and protects 20 ns of work. What percentage of the time is spent in the critical section's work?
Check
Two threads each perform 4 unprotected increments (load, add, store) on a counter starting at 0. What's the smallest final value some interleaving can produce?
Check
8 cores could each do 100 million increments a second on private counters. By what factor does that beat one shared atomic counter whose cache line takes 100 ns per handoff?
Check
Enumerate every interleaving of two threads that each do k = 2 increments as two steps, a load into a private register and a store of that register plus one, to a shared counter starting at 0. Count the distinct schedules (total), how many give the correct 2*k (correct), and the smallest final value (worst). Use itertools.combinations to choose which of the steps belong to thread 0.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
About how many million updates per second can a shared atomic counter handle if each cache-line handoff takes 80 ns?
Check
A contended lock costs 60 ns to acquire and guards 30 ns of work. How many million critical sections per second complete?
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C8