4 ms·
Ordering is basically an unspecified behavior in C. An optimizers best friend is the ability to reorder, perform CSE, etc. C and C++ are specified as the behav
by evanphx 13y ago
Ordering is basically an unspecified behavior in C. An optimizers best friend is the ability to reorder, perform CSE, etc.
C and C++ are specified as the behavior of a straight-line sequence of code run in isolation. Basically, any concurrent C/C++ program treads into the unspecified behavior area. Thusly it's not the optimizers fault, but C/C++ certainly aren't helping out at all.
Even the mechanisms that are common place to make a concurrent C/C++ program run correctly basically wade into unspecified behavior, for instance using asm("lock esp"), asm("mfence"), etc.
TL;DR: concurrency is unspecified in C.
- ohazi 13y ago> TL;DR: concurrency is unspecified in C. One of the many reasons I'm eagerly the 1.0 release of Rust.
- swordswinger12 13y agoI think you accidentally a word.
- AaronFriel 13y agoJust a Heisenbug, he was using a browser written in C or C++.
- theseoafs 13y agoLooks like we've found a compiler bug. Who has Stallman's email?
- ohazi 13y agosigh Yeah, my edit window expired. Very eagerly awaiting. :-P
- frozenport 13y ago>TL;DR: concurrency is unspecified in C. Does the same argument apply to binary code ran on a preemptive operating systems? The actual execution order of your code is still unspecified, as the OS an interrupt it whenever it wants.
- Dylan16807 13y agoMostly. The OS and hardware will make certain guarantees about ordering and concurrency, and if you want more you need to specifically ask them for more. C makes almost no guarantees, but the basic concept is the same. Use the provided extensions to get safe order and concurrency.
- detrino 13y agoC11/C++11 define a memory model and provide assorted primitives.
- letzjuc 13y agoIndeed. It should be: >TL;DR: concurrency is unspecified in _C99_. Since it is specified in C11's memory model.