Threads and Shared Variables in C++11

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
The C++11 standard introduces threads into the language, and carefully defines the meaning of variables shared between threads. The design is based on the idea that meaningful multithreaded programs should, by default, behave as though threads were executed in simple interleaved fashion. This allows efficient execution only because "data races" (simultaneous non-read-only accesses to shared variables) are disallowed. Although this basic approach is shared with some other languages, and with threads interfaces like pthreads, we tried hard to avoid their mistakes. For example, C++11 provides a comprehensive atomic operations library, which makes it much more feasible to avoid data races in real low-level code. Ill give a very quick overview of thread support in C++11, and then focus on the behavior of shared variables, often called the "memory model". Ill try to explain why, after more than 40 years of programming with shared variables, shared variables and atomic operations were still controversial, and why the C++11 approach is the right one. <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Feeds/RSS&WT.dl=0&WT.sessionid=Session:RSSView:8ceeaa3d551e4184a9649fd4012cb54e

View the full article
 
Back
Top