Optimization barriers | Pintos Documentation
An optimization barrier is a special statement that prevents the compiler from making assumptions about the state of memory across the barrier. The compiler will not reorder reads or writes of variables across the barrier or assume that a variable’s value is unmodified across the barrier, except for local variables whose address is never taken. In Pintos, threads/synch.h defines the barrier() macro as an optimization barrier. One reason to use an optimization barrier is when data can change asynchronously, without the compiler’s knowledge, e.g. by another thread or an interrupt handler. The too_many_loops function in devices/timer.c is an example. This function starts out by busy-waiting in a loop until a timer tick occurs: Without an optimization barrier in the loop, the compiler could conclude that the loop would never terminate, because start and ticks start out equal and the loop itself never changes them. It could then “optimize” the function into an infinite loop, which would def
Optimization barriers | Pintos Documentation Skip to main content Menu Expand (external link) Document Search Copy Copied Pintos Documentation Optimization barriers An optimization barrier is a special statement that prevents the compiler from making assumptions about the state of memory across the barrier. The compiler will not reorder reads or writes of variables across the barrier or assume that a variable’s value is unmodified across the barrier, except for local variables whose address is never taken. In Pintos, threads/synch.h defines the barrier() macro as an optimization barrier. One r
related reading
- Memory Barriers Are Like Source Control Operationspreshing.com
- Linux kernel memory barriers — The Linux Kernel documentationdocs.kernel.org
- abseil / Performance Hintsabseil.io
- Who ordered memory fences on an x86? | Bartosz Milewski's Programming Cafebartoszmilewski.com
- Disabling interrupts | Pintos Documentationcs162.org
- Understanding threads | Pintos Documentationcs162.org
- research!rsc: Hardware Memory Models (Memory Models, Part 1)research.swtch.com
- The Go Memory Model - The Go Programming Languagego.dev
- Optimization of Computer Programs in Cicps.u-strasbg.fr
- Compiler Optimizations Are Hard Because They Forget - Faultlorefaultlore.com
- C++11 Memory Modelpeople.cs.pitt.edu
- Barrier function - Wikipediaen.wikipedia.org