From the blog

vcpkg 2023.06.20 and 2023.07.21 Releases: GitHub Dependency Graph Support, Android Tested Triplets, Xbox Triplet Improvements, and More…

vcpkg 2023.06.20 and 2023.07.21 Releases: GitHub Dependency Graph Support, Android Tested Triplets, Xbox Triplet Improvements, and More… Augustin Popa July 31st, 20231 3 The 2023.07.21 release of the vcpkg package manager is available. This blog post summarizes changes from April 16th, 2023 to July 21th, 2023 for the Microsoft/vcpkg, Microsoft/vcpkg-tool, and Microsoft/vcpkg-docs GitHub repos. Some stats for this period: 59 new ports were added to the open-source registry. If you are unfamiliar with the term ‘port’, they are packages that are built from source and are typically C/C++ libraries. 976 updates were made to existing ports. As always, we validate each change to a port by building all other ports that depend on or are depended by the library that is being updated for our nine main triplets. There are now 2,249 total libraries available in the vcpkg public registry. 87 contributors submitted PRs, issues, or participated in discussions in the repo. The main vcpkg repo has over 5,500 forks and 19,300 stars on GitHub.   Notable Changes Notable changes for this release are summarized below:   GitHub Dependency Graph API In June, we announced vcpkg integration with the GitHub dependency graph. This is available for all vcpkg users on the 2023.07.21 release. If you are a GitHub user, we highly recommend checking it out to visualize your repo’s dependencies. We will continue building on this integration in the future and are looking for feedback! PR: Microsoft/vcpkg-tool/#989   Android Tested Triplets We have promoted several Android community triplets to tested triplets. This means they are now tested and validated on all port changes (as of the 2023.06.20 release) and will be listed in the tested triplets table in each release. The new Android tested triplets are: arm-neon-android x64-android arm64-android PR: Microsoft/vcpkg/#29406   Xbox Triplet Improvements In a previous release, community triplets were released for vcpkg users wishing to target Xbox. In this release, several improvements were made to this experience: Added a post build check that libraries don’t link with kernel32, as Xbox does not have kernel32. GameDKLatestis now included in binary cache keys. Xbox triplets require the user of the GameDK, GRDK, and GXDK headers which are supplied through external environment variables. With this change, binary caching will track the version of these dependencies for the purpose of determining when a binary can be restored without re-building. Improvements to triplet selection and turning on the xbox identifier. PR: Microsoft/vcpkg-tool#1059   Updates to depend-info Command vcpkg depend-infodisplays all transitive dependencies for a package in several formats, including plain text, DGML, DOT, etc. This feature can be useful to gain a better understanding of a package’s dependency graph. A user contribution recently added the Mermaid format as an additional option. Furthermore, we made some changes to the way depend-info is used by moving the display options under a common –format subcommand. We believe this layout will make it easier to scale this feature in the future if we add further formatting styles. For more details on how to use depend-info after these changes, see our vcpkg depend-info documentation. PRs: Microsoft/vcpkg-tool/#1080, Microsoft/vcpkg-tool/#935 (thanks @WimLefrere!)   Allow vcpkg remove, export, and x-package-info without overlay triplets In cases where a vcpkg user creates and manages overlay triplets, the commands vcpkg remove, export, and x-package-info can now be run without having to specify those overlay triplets […]

Read More

What’s New for C++ Developers in Visual Studio 2022 17.7

What’s New for C++ Developers in Visual Studio 2022 17.7 Sy Brand August 8th, 20233 2 We are happy to announce that Visual Studio 2022 version 17.7 is now generally available! This post summarizes the new features you can find in this release for C++. You can download Visual Studio 2022 from the Visual Studio downloads page or upgrade your existing installation by following the Update Visual Studio Learn page. Core Editor Comparing Files You no longer need to leave Visual Studio and rely on other tools to compare files. Now you can easily compare any file in Solution Explorer with other files by either: Right-clicking on a single file, selecting “Compare With…” from the context menu which will bring up File Explorer. Navigating to any file on disk and selecting it for comparison. Multi-selecting two files by holding down Ctrl then right-clicking and selecting “Compare Selected” from the context menu. Please share your feedback here.  We’d love to hear your thoughts on this new experience. Copy and Trim Indentation If you have ever copied code from Visual Studio to another application (Outlook, Teams, Slack, etc.) and found that your code indentation has not been copied correctly, you will find that this new capability fixes that for you. Visual Studio now automatically fixes indentation for you when you copy code from Visual Studio and paste it in another application. Parallel Stack Filtering You can use the updated Parallel Stack filtering options that let you selectively display or hide specific threads or frames. This means you can easily concentrate on the threads and frames that are important to you, giving you a clearer picture. Additionally, you can now Drag Select frames from the parallel stack window, allowing you to perform operations like copy/paste, flag/unflag, or freeze/thaw for all the selected frames at once. F5 Speed We have optimized Program Database (PDB) files, resulting in improving debugging sessions and decreasing the project selection screen loading time for Unreal projects for example by 21% (~4 sec gain). Additionally, the F5 path is optimized, leading to a 5-10% improvement in the debugger’s startup time and process launch. All-in-One Search Responsiveness Several accuracy and performance enhancements are coming to All-in-One Search. For example, exact matches now show higher in the results list and results update more accurately in real time as you type your query. Try out the All-In-One Search experience by making sure it is enabled in Tools > Manage Preview Features > “New Visual Studio Search experience (restart required)” and using the Ctrl + T or the Ctrl + Q keyboard shortcut to launch it. If you have feedback to share with us about this feature, let us know here. Find in Files Search Time Find in Files search time has been significantly improved with various optimizations, resulting in a 2x speedup. Game Development C++ Build Insights Thanks to your feedback, we are happy to announce that Build Insights is now integrated with Visual Studio 2022! Build Insights provides you with valuable information needed when optimizing your C++ build times. Start your Build Insights .etl trace capture with a click of a button for your solution or projects. In Visual Studio 17.7, you can now see Included Files and Include Tree view. For advanced profiling, click the “Open in WPA” button to see the trace in Windows Performance Analyzer. After compilation, Build Insights […]

Read More

Learn Multi-threading with Concurrency Support Library in C++

Hello again, as I write this it’s another blazing hot summer week for me, but we don’t let that get in the way of coding and teaching you on our LearnCPlusPlus.org web page. CPUs and GPUs have evolved year on year to feature a greater number of cores and transistors to give more computational power for today’s servers and computers. With the advent of multiple cores, it is common now for programs to make use of multiple simultaneous threads. Multi-threading is one of the great features of modern C++, allowing you to use the maximum number of cores and threads of your CPUs today. For example, the AMD EPYC 9654 with 96 cores 192 threads, or the Intel Xeon w9-3495X 56 cores 112 threads – unimaginable power for anyone looking for CPUs just a decade ago. That power means you can speed up your operations by 2 to 192 times with multi-core CPUs today or you can improve it by 2 or more parallel CPUs.  In modern C++, multi-thread operations are amazingly evolved since C++11, and still there are new improvements in the latest standards to enhance multi-thread operations further. The Concurrency Support Library is designed to solve problems that arise with multi-thread operations and this week we have some examples of multi-threading in C++. This week, we explain what std::thread is and how can we use it with vectors and functors. In multi-threading, concurrency control is important and there is also mutex mutual exclusion and we explain it with very simple, easy to understand examples. We have two more important post picks about the features that come with C++11. The C++11 standard provides an alternative to std::move, which is std::move_if_noexcept and we have examples about it. Unions are rarely used but are another important data type alternative to structs and classes. The C++11 standard loosens up the restriction regarding members of unions, and in the last post, we explain the unrestricted unions feature that came with C++11. Table of Contents Where can I learn C++ with a free C++ compiler? How to use modern C++ with C++ Builder? How to learn C++ for free using C++ Builder? What is new in C++ Builder CE? What might be next for C++ Builder? Where can I learn C++ with a free C++ compiler? If you don’t know anything about C++ or the C++ Builder IDE, don’t worry, we have a lot of great examples on the LearnCPlusPlus.org website and they’re all completely free. Just visit this site and copy and paste any examples there into a new Console, VCL, or FMX project, depending on the type of post. We keep adding more C and C++ posts with sample code. In today’s round-up of recent posts on LearnCPlusPlus.org, we have new articles with very simple examples that can be used with: The free version of C++ Builder 11 CE Community Edition or a professional version of C++ Builder  or free BCC32C C++ Compiler and BCC32X C++ Compiler or the free Dev-C++ Read the FAQ notes on the CE license and then simply fill out the form to download C++ Builder 11 CE. How to use modern C++ with C++ Builder? In C++, vectors are a modern and very flexible form of array in modern C++. Maybe we can say they are like modern linked lists. We can use vectors with std::thread classes for multi-thread operations. In the next […]

Read More

Explicit Virtual Override And More In Modern C++

Hello everyone, I hope now you, your computer, and your development software are enjoying your summer vacation, or at least you’re happy with your work ???? Over on LearnCPlusPlus.org, we add new C++ posts every day. These are good to learn the features of modern C++ compilers. In this round-up of recent articles, we explain some features of C++11 that tend to tighten the rules, to detect some problems that often arise by the virtual overrides. To achieve this goal, C++11 introduced two new contextual keywords, the final and the override specifiers. In this post we explain, what is the virtual function specifier, what is override specifier, what is the explicit virtual override specifier, and how to use the final and the override specifiers. In addition, we explain how the range-based for loop works in modern C++. We try to explain each topic by giving very simple C++ samples and by using more complete C++ examples to highlight modern way of programming. Table of Contents Where can I learn C++ with a free C++ compiler? How to use modern C++ with C++ Builder? How to learn modern C++ for free using C++ Builder ? What is new in C++ Builder CE? What might be next for C++ Builder? Where can I learn C++ with a free C++ compiler? If you don’t know anything about C++ or the C++ Builder IDE, don’t worry, we have a lot of great examples on the LearnCPlusPlus.org website and they’re all completely free. Just visit this site and copy and paste any examples there into a new Console, VCL, or FMX project, depending on the type of post. We keep adding more C and C++ posts with sample code. In today’s round-up of recent posts on LearnCPlusPlus.org, we have new articles with very simple examples that can be used with: The free version of C++ Builder 11 CE Community Edition or a professional C++ Builder  or free BCC32C C++ Compiler and BCC32X C++ Compiler or the free Dev-C++ Read the FAQ notes on the CE license and then simply fill out the form to download C++ Builder 11 CE. How to use modern C++ with C++ Builder? In modern C++ software, a virtual function is a function in a base class or struct that can be redefined in derived classes or structs. They are member functions whose behavior can be overridden in derived classes. The virtual function specifier is the ‘virtual’ specifier to declare a virtual function in a base class. In the first post, we explain how we can use virtual function specifiers in modern C++.How to learn C++ for free using C++ Builder CE? https://learncplusplus.org/what-is-a-virtual-function-specifier-in-modern-c/ The for loops are one of the great features of C and C++ language that has many options to break, continue, or iterate in a loop. In modern C++, there is a range-based for loop that makes it simple to iterate through a variable type that has members (i.e. strings, lists, arrays, vectors, maps, etc.). The range-based for loop is a feature for the for() loops introduced by the C++11 standard and in the next post, we explain what is range-based for loop. https://learncplusplus.org/what-is-a-range-based-for-loop-in-modern-c/ Modern C++ has many additions compared to the original C++ standard. Regarding virtual overrides, C++11 tends to tighten the rules, to detect some problems that often arise. To achieve this goal C++11 introduces two new contextual keywords, the final and the override specifiers. The override specifier is used to redefine the base class […]

Read More

Learn More About std::thread In Multi-Threading Apps

Hello C++ developers, last week we had Coding Bootcamp 2023 by Embarcadero, and Summer Code Fest 2023 by Whole Tomato, and even in heavy weeks like that, Ian Barker still kindly reviews my posts as we both try to keep adding new articles for you. Our educational LearnCPlusPlus.org web page is growing thanks to you, and we have many new readers, thanks to your support. The site features posts which are great to learn the features of modern C++ compilers with very simple explanations and examples. In this round-up of recent articles, we explain the multi-threading features of modern C++ along with other useful methods for developers. In modern C++, multi-thread operations have evolved amazingly since C++11, and still, there are new improvements in the latest standards to enhance multi-thread operations further. The Concurrency Support Library is designed to solve problems that arise with multi-thread operations and this week we have some examples of multi-threading in C++. We explain the very useful multi-threading class std::thread with very simple examples that everyone can use with their functions, and we explain how we can use lambda expressions with std::thread in C++ with examples. C++11 adds atomic types and operations to the standard and we explain what is atomic type in C++. C++11 introduced new forms of literals using modified syntax and semantics to provide User-Defined Literals (UDL) also known as Extensible Literals and we explain how to use user-defined literals. C++11 standard improved the previous C99 standard feature __func__ and in the last post today we explain how to use user-defined literals. Table of Contents Where can I learn C++ with a free C++ compiler? How to use modern C++ with C++ Builder? How to learn C++ for free using C++ Builder? Learn To Use Predefined Identifier __func__ In C++ What is new in C++ Builder 12? What might be next for C++ Builder? Where can I learn C++ with a free C++ compiler? If you don’t know anything about C++ or the C++ Builder IDE, don’t worry, we have a lot of great examples on the LearnCPlusPlus.org website and they’re all completely free. Just visit this site and copy and paste any examples there into a new Console, VCL, or FMX project, depending on the type of post. We keep adding more C and C++ posts with sample code. In today’s round-up of recent posts on LearnCPlusPlus.org, we have new articles with very simple examples that can be used with: The free version of C++ Builder 11 CE Community Edition or a professional version of C++ Builder  or free BCC32C C++ Compiler and BCC32X C++ Compiler or the free Dev-C++ Read the FAQ notes on the CE license and then simply fill out the form to download C++ Builder 11 CE. How to use modern C++ with C++ Builder? In modern mathematics, physics, and computer science; optimized and faster app development in programming is very important to speed up computations. CPUs and GPUs are highly evolved by the number of cores and transistors to give more computational power to today’s servers and computers. Thus, we can use more cores and threads in our applications by using std::thread. We can use the std::thread class in multi-thread operations, and in the first post pick, we explain how to use std::thread and how can we use it with modern C++ examples. Lambda Expressions allow users to write an inline expression that can be used for short snippets of code that are not going to […]

Read More

Powerful Atomic Operations In C++ – No Oppenheimer Required

Hello C++ developers, Yilmaz here from LearnCPlusPlus. RAD Studio’s C++ Builder, Delphi and their free community editions C++ Builder CE, and Delphi CE are a real force for modern application development. Our educational LearnCPlusPlus.org web page is another powerful element for learning details of modern C++ programming. It is growing well thanks to you, and we have many new readers, thanks to your support! The LearnCPlusPlus.org site has unique and new posts with examples suitable for everyone from beginners to professionals alike. The site features a plethora of posts which are great to learn the features of modern C++ compilers with very simple explanations and examples. In this round-up of recent articles, we explain atomics and atomics operations, which are the multi-threading features of modern C++ along with other useful methods for developers. You don’t have to be Robert Oppenheimer to get to grips with atomic operations in C++ so put away your safety googles and relax as we take you through the details. In modern C++, multi-thread operations have evolved amazingly since C++11, and still, there are new improvements in the latest standards to enhance multi-thread operations further. The concurrency support library in modern C++ is designed to solve problems in multi-thread operations. Since the C++11 standard, this library includes built-in support for threads (std::thread) with atomic operations (std::atomic). Table of Contents Where I can I learn about atomic operations in C++ with a free C++ compiler? How can I use atomic operations in C++ Builder? What are atomic operations in C++ and how can I use them? Do you want to know some more on what is planned for C++ Builder 12? What might be next force may be for C++ Builder? Where I can I learn about atomic operations in C++ with a free C++ compiler? If you don’t know anything about C++ or the C++ Builder IDE, don’t worry, we have a lot of great examples on the LearnCPlusPlus.org website and they’re all completely free. Just visit this site and copy and paste any examples there into a new Console, VCL, or FMX project, depending on the type of post. We keep adding more C and C++ posts with sample code. In today’s round-up of recent posts on LearnCPlusPlus.org, we have new articles with very simple examples that can be used with: The free version of C++ Builder 11 CE Community Edition or a professional version of C++ Builder  or free BCC32C C++ Compiler and BCC32X C++ Compiler or the free Dev-C++ Read the FAQ notes on the CE license and then simply fill out the form to download C++ Builder 11 CE. How can I use atomic operations in C++ Builder? The concurrency support library in modern C++ is designed to solve problems in multi-thread operations. Since the C++11 standard, this library includes built-in support for threads (std::thread) with atomic operations (std::atomic). C++11 adds atomic types and operations to the standard. Atomic types and operations provide a way of writing multi-threaded applications without using locks. In the next post, we explain what is std::atomic and how we can use atomic types efficiently in modern C++. Atomic types are special in multi-threading operations and they can be used to count things, to sum, and to calculate some data types. The fetch_add and the fetch_sub are atomic addition operations that atomically replaces the current value with the result of arithmetic addition or subtraction of the given value. […]

Read More

Important To Learn std::memory_order In C++ Atomic Operations

Using multi-threading development skills on the CPU, GPU, and memory operations is important in programming, but it can give rise to problems in synchronization of multi-thread operations and reaching data for reading and writing. The concurrency support library in modern C++ is designed to solve problems in multi-thread operations. Since the C++11 standard, this library includes built-in support for threads (std::thread) with atomic operations (std::atomic). The memory_order type definition defines how to access memory in multi-thread operations, including atomic, regular, and non-atomic memory accesses. In this post, we explain how to use std::memory_order in modern multi-threading operations. Concurrent programming is highly evolved and inherently diverse, and includes high-performance multi-threading and parallel programming features, asynchronous task processing, message-based and event-based systems, non-blocking, lock-free, and optimistic data structures, transactional approaches, and many other features to build multi-threading applications. The memory_order feature is one of the most important parts of the new C++ standards. For example, the C++20 standard has about 653 “memory_order” keywords if you perform a search. In other words, it means it has a very important role in atomic and atomic operations in multi-threading applications. Before this, let’s remind ourselves about std::atomic in C++. What is atomic (std::atomic) in C++? C++11 adds atomic types and operations to the standard. Atomic types and operations provide a way of writing multi-threaded applications without using locks. In modern C++, the std::atomic template class is defined in the header and it can be used to wrap other types to do atomic operations on that type. When a thread writes to an atomic object another thread can read from it. Every instantiation and full specialization of the std::atomic template defines an atomic type. Atomic types ensure any read or write operation synchronizes as part of multi-thread operations, (i.e. using these types in std::thread). They work well on private types (i.e. int, float, double, etc.) or any type that is trivially copyable types which means it has at least one eligible copy constructor, move constructor, copy assignment operator, or move assignment operator and has non-deleted trivial destructor. Here is a simple syntax for the atomic declaration:   atomic type_name;   Here is a simple std::atomic example:   std::atomic counter(0); // atomic type   void myf() // a function to be used in multi-thread operations {    counter++; // atomic operation }   Atomic operations are operations on the of values atomic types (std::atomic objects) in the atomic library that allows lockless concurrent programming. These operations are good in data races and these objects are free of data races. Different atomic operations can be done on the same atomic object in their sync. std::atomic has many features to be used in atomic operations, i.e. load, store, operator=, wait, exchange, is_lock_free, etc. Let’s see these load and store operations now. What is std::memory_order in C++ atomic operations? The memory_order type definition defines how to access memory in multi-thread operations, including atomic, regular, and non-atomic memory accesses. The memory_order type definition is used in multi-thread atomic operations when multiple threads simultaneously read and write to different variables in memory. In this concept, threads can observe the value changes in order or threads written into atomic types within memory order. Here is the definition syntax from C++11 to C++17,   typedef enum memory_order {     memory_order_relaxed,     memory_order_consume,     memory_order_acquire,     memory_order_release,     memory_order_acq_rel,     memory_order_seq_cst } memory_order;   Since C++20, there are changes on this […]

Read More

Learn Useful Bidirectional Fences In Modern Multi-threading C++ Apps

C++11 improved the support for bidirectional fences in multi-thread applications. In modern C++ development, Fences are synchronization primitives in multi-threading operations, they are memory barriers in threads, and they can acquire semantics, release semantics, or both. In this post, we explain what are fences and how we can use them. What are bidirectional fences in C++? A fence is a primitive that enforces ordering between preceding loads or stores and subsequent loads or stores. C++11 improves the support for bidirectional fences. Fences are synchronization primitives in multi-threading operations they can have acquire semantics, release semantics, or both of them. A fence with acquire semantics is called an acquire fence and a fence with release semantics is called a release fence. If both operations are done, we call them full fence.  In modern C++, std::atomic_thread_fence is called fences, they are memory barriers in multi-thread operations, and they establish synchronization and ordering constraints between each thread without any atomic operation. In other words, std::atomic_thread_fence establishes memory synchronization ordering of non-atomic and relaxed atomic accesses without an associated atomic operation. How to use bidirectional fences in C++? Fences are useful between load and store operations and there are 4 types . LoadLoad : A load followed by a load LoadStore : A load followed by a store StoreLoad : A store followed by a load StoreStore : A store followed by a store Here is the syntax how we can use std::atomic_thread_fence,   extern “C” void atomic_thread_fence( std::memory_order order ) noexcept;   Here are two simple examples how to use in release and acquire operations of thread functions,   void myf1() {       atomic_thread_fence(std::memory_order_release); }     void myf2() {          atomic_thread_fence(std::memory_order_acquire); }   according to open-std.org document , depending on the value of memory_order, this operation it has different effects, if order == memory_order_relaxed; it has no effects, if order == memory_order_acquire || order == memory_order_consume; it is an acquire fence, if order == memory_order_release; it is a release fence, if order == memory_order_acq_rel; it is both an acquire fence and a release fence, (full fence) if order == memory_order_seq_cst; it is a sequentially consistent acquire and release fence Is there a full C++ example of how to use bidirectional fences in C++? Let’s assume we have two threads one is writing to data other one is reading 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27   #include #include   int x[500];   void myf1() { for (int i = 0; i

Read More

What Is A Data Race In Multi-threading C++ Apps And How To Avoid It

In modern programming, if you are developing multithreaded applications, data races are a common problem in threads. Data races occur when multiple tasks or threads access a shared resource without sufficient protection, leading to undefined or unpredictable behavior on runtime. You can imagine two or more task threads in cores trying to reach the same data in a race. In this post, we explain what a data race is and how to avoid it in modern C++. What is data race in multi-threading C++ apps? We use multi-threading code when we want to handle multiple tasks to speed up functions or algorithms. Multithreaded programming is easy with the concurrency support library in C++. However, if you don’t know how to reach each data type, multi-thread operations can be highly complex and introduce subtle defects such as data races and deadlocks. At this time, defects occur on runtime or at outputs, this may take a long time to reproduce the issue and even longer to identify the root cause and fix the defect. In general, more than one thread accesses the same memory location simultaneously, and at least one writes in data race situations. That means there is a conflict in memory access. Is there an example of a data race in C++? Assume that we have a computer shop, and we have items in the store. We move them from shop to store and from store to shop. We have many staff (threads) that transfer these items from store to shop or shop to store. Different staff may access the store or shop at the same time. In this simple data race example, the same thread function ( transfer_items() ) reads and writes two different variables (store_items and shop_items) where they show the number of items in store and shop. Here is a full example, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30   #include #include   int store_items = 20; int shop_items = 0; //—————————————————————— void transfer_items(int amount, int& out, int& in) {   out -= amount;   std::this_thread::sleep_for(std::chrono::nanoseconds(10));   in += amount; } //—————————————————————— int main() {   std::cout

Read More

How To Solve Data Race Problems In Modern C++?

In multi-thread programming, data races are a common problem in threads. Data races occur when multiple tasks or threads access a shared resource without sufficient protection, leading to undefined or unpredictable behavior on runtime. In C++, the concurrency support library is designed to solve these kinds of data race problems. In this post, we explain how to solve data race problems in modern C++. What is data race in multi-threading C++ apps? We use multi-threading code when we want to handle multiple tasks to speed up functions or algorithms. Multithreaded programming is easy with the concurrency support library in C++. However, if you don’t know how to reach each data type, multi-thread operations can be highly complex and introduce subtle defects such as data races and deadlocks. At this time, defects occur on runtime or at outputs, this may take a long time to reproduce the issue and even longer to identify the root cause and fix the defect. How can we solve data race problems with modern C++? If you have a problem in your multi-threading application and you understand that is about data racing in threads. First, if your app is popular and you want to fix and release it quickly, set it to a single thread (slower but faster and safer and gives you time to solve the problem). Thus, your application may run, with slower performance, but no defects during runtime. Now we can focus on our real problem. First, know that the data race problem is about accessing your data in usage in your threads. Try to find which thread is causing this, and what type of data could be having a situation that at least one operation in threads trying to write. Debugging in thread operations may help you and try to slow your thread by using sleep_for in threads.   std::this_thread::sleep_for(std::chrono::milliseconds(1000));   If your debugger doesn’t help, you can ‘comment’ some parts of data write operations. Inside a thread, between the suspicious lines, you can add some printouts into a variable (to string lists for example) to see each operation step in debug before the error occurs. In deep, you can use every feature of the concurrency support library in C++, we highly recommend you C++17 or higher compilers to achieve better results in usage. Use std::thread, and std::atomic with atomic types and operations (load, store), and you can use memory order (std::memory_order) models in different situations. Moreover, you can use fences (std::atomic_thread_fence), mutex (std::mutex) and other blocking or locking methods in threads.  The concurrency support library is designed to solve these kinds of data race problems. This is your exact solution and there might be different ways to solve with different concurrency features in modern C++. Note that, there might be slight differences in operational speed and thread usage, so you should decide which feature is the best for your thread function or functions. They may help your algorithm to speed up and to be safer too. Solving multi-thread problems may require high programming skills, if you are still unable to solve problems, you may get additional support from senior C++ developers or supporter developers of your IDE and compiler. Is there a data race example in modern C++? Assume that we have a computer shop and we have items in the store. We move them from […]

Read More