'Memory leaks using shared_mutex
The following code leads into an increasing usage of memory:
#include <shared_mutex>
class foo
{
public:
void bar()
{
std::unique_lock lock(m_mtx);
}
std::shared_mutex m_mtx;
};
int main()
{
while (1)
{
foo obj;
obj.bar();
}
}
The following do not: (only changes the mutex type)
#include <mutex>
class foo
{
public:
void bar()
{
std::unique_lock lock(m_mtx);
}
std::mutex m_mtx;
};
int main()
{
while (1)
{
foo obj;
obj.bar();
}
}
I am using Windows 7 and using the task manager to track the memory consumption of my program.
I compile with mingw and this simple command line to compile:
g++.exe -std=c++17 -o mytest main.cpp
What i am doing wrong with the usage of shared_mutex ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
