Last active
February 24, 2020 05:45
-
-
Save arcticmatt/7e2dde243370c14e37ed34b112f6b4aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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