Threads were introduced in C++ as part of the C++ 11 standard. It’s been a while, one should say! Using thread is pretty straightforward, yet beginners might face some challenges in managing the lifecycle of the thread objects. This article is intended to be used as a reference to use the threads in the right way! So, Let’s go ahead, create a thread and give it some task!

#include <iostream>
#include <thread>
using namespace std;
void foo() {
cout << "some work" << endl;
}
int main() {
thread t(foo);
}

But wait! This code crushes! A slight deep dive…


No matter what level of proficiency someone has in C++ or any other programming language for that matter, when asked about design patterns, Singleton has got to be the first one that pops into the head. If you are reading this post, I am pretty sure you would have already used it at-least once in your career as a programmer.

On the other hand, there are many concerns on using it like it being an anti pattern, cannot be unit tested, and n number of other reasons. It is true that singleton is not the solution for every problem, but…

Ravi Teja Narra

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store