Fluent::Programmer

    Home Blog About
  • Home
  • Blog
  • About

Beautiful code series

Fluent Programmer wrote

Beautiful code #9 - Restrict access to memory location for threads using mutex, cv, bool flag in multi threading (C++) 👋

To restrict access to a memory location in C++ to only certain threads, you can use a combination of synchronization primitives such as mutexes and condition variables. Here’s an example that demonstrates how to achieve this:

Fluent Programmer wrote

Beautiful code #8 - Conditional variable in multi threading (C++) 👋

Here is an example of a C++ threading code that demonstrates how to use multiple threads and synchronize them using condition variable. This is basic producer-consumer scenario of how Apache Kafka streams data.

Fluent Programmer wrote

Beautiful code #7 - std::thread, std::accumulate 👋

Here is an example of C++ threading code that demonstrates how to use multiple threads to calculate the sum of an array of numbers. I will provide a detailed explanation of the code afterwards.

Fluent Programmer wrote

Beautiful code #6 - std::copy_if, std::remove_copy_if, std::copy, std::execution::par_unseq, std::back_inserter 👋

std::copy_if, std::remove_copy_if, std::copy, std::back_inserter, and std::execution::par_unseq are features from C++11 and C++98 that helps efficiently copy from one data structure to the another.

Fluent Programmer wrote

Beautiful code #5 - std::for_each, std::ranges::for_each, std::optional, std::execution::par_unseq, mutable 👋

std::for_each, std::ranges::for_each, std::optional, and std::execution::par_unseq are features from C++20 and C++23 that helps efficiently loop through the loop, loop in parallel, add optional values in the data structure of your choice, etc.

Fluent Programmer wrote

Beautiful code #4 - std::any_of, std::none_of, std::all_of - efficient C++20 feature👋

std::any_of, std::none_of and std::all_of is a C++20 feature that helps efficiently check for basic conditions in the data structures. This is very optimal because of early termination once some fact is found and the algorithm don’t have to iterate more to further prove anything before returning the result.

Fluent Programmer wrote

Beautiful code #3 - [[no_unique_address]] - sophisticated and simple C++20 feature👋

[[no_unique_address]] is a C++ 20 feature that helps in saving memory while declaring an empty struct or class and creating object for it in some other place.

  • ««
  • «
  • 1
  • 2
  • »
  • »»
  • C++
  • Beautiful code series

Unhealthy love with dark corners of C++

Founded by an engineer to help engineers. 2021–2023.

  • About us
  • Privacy policy