nkr
A C++20 library with a custom meta-programming language.
nkr::concurrency Namespace Reference

Concurrency types are used to make other types work in a concurrent or parallel context. More...

Detailed Description

Concurrency types are used to make other types work in a concurrent or parallel context.

Most modern computers come with more than one CPU core, making it possible to compute more than one thing at the same exact time. This namespace contains types that allow you to take advantage of the available CPU cores in a controlled manner, so that shared data will not be clobbered and so synchronization, i.e. the timing of pre and post concurrency execution, can properly occur.

Note
Concurrency is analogous to using your right hand to perform one task while simultaneously using your left hand to perform another. There are different types of concurrency, and in particular there are two primary way to do it. I encourage you to always consider each before adopting concurrency into your code:
  1. Sometimes you have totally different tasks for each hand to do, and they may not take the same amount of time - thus when one hand finishes a job it is free to begin another while the other hand is still working on the first. This gives each hand the opportunity to always be doing something instead of having to wait on each other.
  2. Other times you may have a single job that you can break into parts, or multiple instances of the same job. Because they should each take about the same amount of time to complete you can coordinate both hands to start and finish each task at the same time. This parallel behavior is an efficient way to plan multiple batches, in this case batches of two jobs at a time, one batch after another.