C: Difference between revisions

Jump to navigation Jump to search
597 bytes removed ,  7 years ago
no edit summary
(Created page with "=C= C is a general-purpose, high-level, imperative programming language created by Dennis Ritchie between 1969 and 1973 at Bell Labs. C is now represented as a number of ISO...")
 
No edit summary
Line 11: Line 11:
=Well-Defined Concurrency and Memory Models=
=Well-Defined Concurrency and Memory Models=


It is important to realize that prior to 2011 ISO C and ISO C++ standards these languages had no definitions of concurrency and memory models. In pre-C11 and pre-C++11 code, while most of the time the "right" thing is done, understand there are no guarantees in the language specifications (and therefore compiler implementations of such) of the ordering of reads and writes under concurrency.
Prior to 2011 the ISO C standard had no definitions of concurrency and memory models, thus, in pre-C11 compiled code there are no guarantees concerning the ordering of memory reads and writes under concurrency, i.e., such is likely undefined behaviour which the compiler vendor may or may not have documented. It is therefore preferable to compile concurrent C code as C11 code (or newer).
 
Prior to C11 and C++11, one would have used the pthreads / Windows threading APIs to implement concurrency. Although many compilers will implement C11 and C++11 threads, etc. in terms of pthreads / Windows threading APIs, using the ISO C++11 and ISO C11 definitions is better for two reasons:
 
* the code is compiler and platform independent, and,
* C11 and C++11 have well-defined memory models --continuing to compile code using pre-C11 and/or pre-C++11 compiler language flags implies that no memory models are formally in effect and that code is likely relying on undefined behaviour(s).


=Pitfalls=
=Pitfalls=
cc_staff
156

edits

Navigation menu