Threading is one of the most complicated things to get right in programming, especially in C++. Bugs are frequently encountered in multithreaded programs more frequently than we would like. Sometimes these bugs tread into production software causing live systems to be patched causing an additional expense.

In this article, I will be highlighting some of the common mistakes I found in various projects using the Coderrect tool.

  1. Not protecting shared data or shared resources

In a program running multiple threads, access to a resource is usually competitive. The threads compete with each other in accessing the shared variable. This often…

Modern computers contain multiple processors, multi-core processors, or hyperthreading processes that can run several simultaneous threads. Parallel processing using many threads can greatly improve program performance, but it may also make debugging more difficult because you’re tracking many threads at a time. Multithreading can also introduce new types of potential bugs like a data race or a deadlock condition which are often hard to identify.

Data Race

It is an error that arises during the execution of a multi-threaded program. A data race occurs when:

  • multiple threads in a single process access the same memory location concurrently, and
  • at least…

Akhil Robertson Cutinha

Get the Medium app
