Skip to content

Instantly share code, notes, and snippets.

@arcticmatt
Last active February 24, 2020 05:45
Show Gist options
  • Save arcticmatt/7e2dde243370c14e37ed34b112f6b4aa to your computer and use it in GitHub Desktop.
Save arcticmatt/7e2dde243370c14e37ed34b112f6b4aa to your computer and use it in GitHub Desktop.
// Problem #1
{
int *arr = new int[dynamicSize];
} // arr goes out of scope but we didn't delete it, we have a memory leak
// Problem #2
std::mutex globalMutex;
void funcCalledInMultipleThreads() {
globalMutex.lock();
// Code that runs in multiple threads...
} // We never unlocked the mutex, so this function will deadlock
// Problem #3
{
std::thread t1([]() {
std::cout << "In a thread" << std::endl;
// Do some stuff...
return 5;
});
} // Thread goes out of scope and is joinable, std::terminate is called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment