This file contains hidden or 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
#include <iostream> | |
#include <mutex> | |
std::mutex globalMutex; | |
class CustomScopedLock { | |
public: | |
CustomScopedLock(std::mutex &m) : m_(m) { | |
std::cout << "CustomScopedLock locking mutex..." << std::endl; | |
m_.lock(); |
This file contains hidden or 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... |
NewerOlder