I keep on hearing about concurrent programing every where. Can you guys throw some light on what it's and how c++ new standards facilitate doing the same?
Concurrent programming allows the execution of multiple threads and thus we can write highly efficient programs by taking advantage of any parallelism available in computer system. C++11 acknowledged the existence of multi-threaded programs and the later standards also brought some improvements.
C++, as defined in the reference manual [ELL90], has no support for the creation or management of concurrent C++ programs. If we are going to use the standard C++ language, we have to rely on the other category of concurrency support.
Concurrency results in resource sharing, which causes issues like deadlocks and resource scarcity. It aids with techniques such as process coordination, memory allocation, and execution schedule to maximize throughput.
concurrent programming, computer programming in which, during a period of time, multiple processes are being executed. For example, two processes can be interleaved so that they are executed in turns.
Concurrency is about your code doing multiple things at the same time. This is typically done with explicit "threads", but there are other possibilities. For example, if you use OpenMP directives in your code then a compiler that supports OpenMP will automatically generate threads for you.
Thread is short for "thread of execution". In a single-threaded C++ program, execution starts at main(), and then proceeds in a sequential fashion. In a multi-threaded program, the first thread starts at main, but additional threads may be started by the application which start at a user-specified function. These then run concurrently, or in parallel with the original thread.
In C++0x threads are started using the std::thread
class:
void my_function() { // do stuff } std::thread my_thread(my_function); // run my_function in its own thread
The new C++0x standard also supports:
std::atomic<>
class template,std::mutex
, std::recursive_mutex
, etc.)std::lock_guard<>
, std::unique_lock<>
)std::lock
and std::try_lock
functions to manage acquiring multiple locks at the same time without risking deadlockstd::condition_variable
, std::condition_variable_any
)thread_local
keyword to declare thread-local dataI gave a more detailed overview of the new C++0x thread library in my article on devx.com: Simpler Multithreading in C++0x
I write about multithreading and concurrency in C++ on my blog. I'm also writing a book on the topic: C++ Concurrency in Action.
When you say "how c++ new standards facilitate" concurrent programming, I assume you're talking about the soon (?) to be released C++09 standard.
The new standard as it currently stands in draft form supports the following items that help with concurrent programming:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With