Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

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.



C11/C++11 define a memory model and provide assorted primitives.


Indeed. It should be:

>TL;DR: concurrency is unspecified in _C99_.

Since it is specified in C11's memory model.


> TL;DR: concurrency is unspecified in C.

One of the many reasons I'm eagerly the 1.0 release of Rust.


I think you accidentally a word.


Just a Heisenbug, he was using a browser written in C or C++.


Looks like we've found a compiler bug. Who has Stallman's email?


sigh Yeah, my edit window expired. Very eagerly awaiting. :-P


>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.


Mostly. 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: