{"id":3309,"date":"2023-08-04T14:46:42","date_gmt":"2023-08-04T18:46:42","guid":{"rendered":"https:\/\/blog.wholetomato.com\/?p=3309"},"modified":"2023-08-15T18:28:00","modified_gmt":"2023-08-15T22:28:00","slug":"summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20","status":"publish","type":"post","link":"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/","title":{"rendered":"Summer CodeFest: Next-Level Concurrency: Enhancing Scalability with C++20 [Recap]"},"content":{"rendered":"<p><strong>This session has concluded<a href=\"https:\/\/youtu.be\/CpWOLeS5v_E\"> watch the replay<\/a> or download the slides below.<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">The first Summer CodeFest presentation has concluded! Whole Tomato\u00e2\u20ac\u2122s very own lead developer Chris Gardner lead the first session on enhancing your program&#8217;s scalability with concurrency techniques in C++!<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We\u00e2\u20ac\u2122ve 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.<\/span><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\r\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\r\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/#What_is_Concurrency\" >What is Concurrency?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/#The_benefits_of_concurrent_processing\" >The benefits of concurrent processing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/#Scaling_programs_using_concurrency_and_multithreading_in_C\" >Scaling programs using concurrency and multithreading in C++<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/#Presentation_Slide_Deck\" >Presentation Slide Deck<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/#Watch_the_Replay\" >Watch the Replay<\/a><\/li><\/ul><\/nav><\/div>\r\n<h2><span class=\"ez-toc-section\" id=\"What_is_Concurrency\"><\/span><span style=\"font-weight: 400;\">What is Concurrency?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"3314\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/microsoftteams-image-4\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?fit=821%2C443&amp;ssl=1\" data-orig-size=\"821,443\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"MicrosoftTeams-image 4\" data-image-description=\"&lt;p&gt;#image_title&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;#image_title&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?fit=300%2C162&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?fit=821%2C443&amp;ssl=1\" class=\"aligncenter wp-image-3314 size-full\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?resize=821%2C443&#038;ssl=1\" alt=\"\" width=\"821\" height=\"443\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?w=821&amp;ssl=1 821w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?resize=300%2C162&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?resize=768%2C414&amp;ssl=1 768w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/MicrosoftTeams-image-4-e1691174739122.png?resize=360%2C194&amp;ssl=1 360w\" sizes=\"(max-width: 821px) 100vw, 821px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p><i><span style=\"font-weight: 400;\">With parallel processing, programs can execute tasks simultaneously instead of sequentially which cuts completion time.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">There is a difference between parallelism and concurrency, but we won\u00e2\u20ac\u2122t 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 <\/span><a href=\"https:\/\/stackoverflow.com\/questions\/1050222\/what-is-the-difference-between-concurrency-and-parallelism\"><span style=\"font-weight: 400;\">here<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_benefits_of_concurrent_processing\"><\/span><span style=\"font-weight: 400;\">The benefits of concurrent processing<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">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 <\/span><i><span style=\"font-weight: 400;\">task switches <\/span><\/i><span style=\"font-weight: 400;\">extremely fast much like our brains.\u00c2\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">With the right conceptual program, computers can employ multiple cores or even virtual threads to run tasks in parallel\u00e2\u20ac\u201dit 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.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">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 \u00e2\u20ac\u0153brain\u00e2\u20ac\u009d.\u00c2\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">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).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The difficulty in learning parallelism is often in how and when these separate threads should communicate with each other.\u00c2\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">(Note: Relatively, C++ is not a concurrency-oriented language because it usually relies on its innate speed to run complex tasks sequentially\u00e2\u20ac\u201dbut that\u00e2\u20ac\u2122s not to say there is no use for parallelism in C++)<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Scaling_programs_using_concurrency_and_multithreading_in_C\"><\/span><span style=\"font-weight: 400;\">Scaling programs using concurrency and multithreading in C++<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">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.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Included in the Standard library are the following tools and features:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">thread-aware memory models<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Classes for managing threads<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Managing and protecting shared data<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Synchronizing operations between threads<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Low-level atomic operations<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">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\u00e2\u20ac\u2122s very own lead developer.<\/span><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?ssl=1\" target=\"_blank\" rel=\"https:\/\/www.wholetomato.com\/landing\/summer-codefest-coding-camp#register noopener\"><img decoding=\"async\" data-attachment-id=\"3312\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/summer-codefest-guide-next-level-concurrency-enhancing-scalability-with-c20\/16_wtsummer-codefest-individual-sessions_chris-gardner_1200x628\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?fit=1200%2C628&amp;ssl=1\" data-orig-size=\"1200,628\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"16_WTSummer CodeFest Individual Sessions_Chris Gardner_1200x628\" data-image-description=\"&lt;p&gt;#image_title&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;#image_title&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?fit=300%2C157&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?fit=1024%2C536&amp;ssl=1\" class=\"aligncenter wp-image-3312 size-medium\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?resize=300%2C157&#038;ssl=1\" alt=\"\" width=\"300\" height=\"157\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?resize=300%2C157&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?resize=1024%2C536&amp;ssl=1 1024w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?resize=768%2C402&amp;ssl=1 768w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?resize=360%2C188&amp;ssl=1 360w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?w=1200&amp;ssl=1 1200w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">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&#8217;s new concurrency features.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p><strong>This session has concluded watch the replay or download the slides below.<\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Presentation_Slide_Deck\"><\/span>Presentation Slide Deck<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><iframe src=\"https:\/\/docs.google.com\/presentation\/d\/e\/2PACX-1vQGtssFLMDnr3QhdIyEGBbx5uQUr4XfZh58caMYTfPvm1TRD4f9rbyJC_7EcKCzB73vEqX2-Otn9qyb\/embed?start=false&amp;loop=false&amp;delayms=3000\" width=\"1080\" height=\"760\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><span data-mce-type=\"bookmark\" style=\"display: inline-block; width: 0px; overflow: hidden; line-height: 0;\" class=\"mce_SELRES_start\">\u00ef\u00bb\u00bf<\/span><\/iframe><\/p>\n<h2><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"Watch_the_Replay\"><\/span>Watch the Replay<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><iframe title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/CpWOLeS5v_E\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This session has concluded watch the replay or download the slides below. The first Summer CodeFest presentation has concluded! Whole Tomato\u00e2\u20ac\u2122s very own lead developer Chris Gardner lead the first session on enhancing your program&#8217;s&#8230;<\/p>\n","protected":false},"author":213500340,"featured_media":3312,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[672,726359896],"tags":[2426,726359920,726359921,726359922],"class_list":["post-3309","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks","category-webinar-recap","tag-c","tag-concurrency","tag-multithreading","tag-parallelism"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2023\/08\/16_WTSummer-CodeFest-Individual-Sessions_Chris-Gardner_1200x628.png?fit=1200%2C628&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfhqii-Rn","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/3309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/users\/213500340"}],"replies":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/comments?post=3309"}],"version-history":[{"count":7,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/3309\/revisions"}],"predecessor-version":[{"id":3331,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/3309\/revisions\/3331"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/media\/3312"}],"wp:attachment":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/media?parent=3309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/categories?post=3309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/tags?post=3309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}