Site icon Tomato Soup

Summer CodeFest: Next-Level Concurrency: Enhancing Scalability with C++20 [Recap]

This session has concluded watch the replay or download the slides below.

The first Summer CodeFest presentation has concluded! Whole Tomato’s very own lead developer Chris Gardner lead the first session on enhancing your program’s scalability with concurrency techniques in C++!

We’ve prepared a short introductory article about concurrency and a short history on C++ support for threads in this article so you can better understand the session.

What is Concurrency?

Concurrency is an umbrella concept that encompasses multithreading and other techniques that are used to handle multiple tasks simultaneously. It involves managing shared resources (like variables, files, memory, etc.) to avoid race conditions and ensure thread safety.

A term that is almost synonymous with concurrency is multithreading. This is the concept of running multiple threads (smaller units of a process) within a single process. Each thread has its own stack and shares the same heap with other threads in the process. Multithreading is useful for parallelizing tasks and taking advantage of modern multi-core processors.

With parallel processing, programs can execute tasks simultaneously instead of sequentially which cuts completion time.

There is a difference between parallelism and concurrency, but we won’t get to that here as we need to dive into concurrency in C++. If you want to learn more about the theories, you can read more about it here.

The benefits of concurrent processing

The two main benefits of using concurrency is performance and division of labor. Learning how to program for multithreading may be hard to wrap your head around at first. Humans are usually sequential when it comes to executing tasks. Similarly, a single CPU core is only ever doing one task at a time, but it task switches extremely fast much like our brains. 

With the right conceptual program, computers can employ multiple cores or even virtual threads to run tasks in parallel—it does not need to fake with fast task switching. This allows your program to actually use memory and variables in such a way that two tasks can access it simultaneously.

For example, in processing-heavy tasks such as HD video playback, you can divide the processing labor between the video crunching and the interface. The first thread will take care of reading the disk, decoding the image and sound bytes, and finally sending the video and sound to the hardware. On the other hand, the second thread can handle the user inputs such as play/pause, stopping, and the like. This allows your program to focus on each task with a separate “brain”. 

The two threads can communicate with each other only when needed so the overall experience is way more responsive (benefits the user) but is also easy to manage the program (benefits the programmer).

The difficulty in learning parallelism is often in how and when these separate threads should communicate with each other. 

(Note: Relatively, C++ is not a concurrency-oriented language because it usually relies on its innate speed to run complex tasks sequentially—but that’s not to say there is no use for parallelism in C++)

Scaling programs using concurrency and multithreading in C++

In C++ 2011, multithreading support was added to the C++ standard. This included useful components and C++ developers were able to use concurrency without the use of environment-specific extensions.

Included in the Standard library are the following tools and features:

To get a better understanding of how to incorporate concurrency and multithreading in your C++ code, sign up for the following tutorial hosted by Whole Tomato’s very own lead developer.

Explore modern C++20 multithreading and powerful parallelism techniques. As programs get more complex, computers get equipped with even more CPU cores. Learn to optimize applications for peak performance with real-world examples and practical insights with C++20’s new concurrency features.

This session has concluded watch the replay or download the slides below.

Presentation Slide Deck

Watch the Replay

 

Exit mobile version