This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/57440] New: Memory usage with future and std containers
- From: "gallardo.d.e at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 28 May 2013 12:49:24 +0000
- Subject: [Bug libstdc++/57440] New: Memory usage with future and std containers
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57440
Bug ID: 57440
Summary: Memory usage with future and std containers
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: gallardo.d.e at gmail dot com
Consider the following test code:
#include <vector>
#include <array>
#include <future>
#include <iostream>
using std::vector;
using std::array;
using std::cout;
using std::endl;
typedef unsigned int uint;
double TestFutures()
{
return 1;
}
void DoWork()
{
const uint nPoints=50;
const uint nThreads=100;
vector<double> results(nThreads,0);
// For each data point...
for (uint k=0; k<nPoints; ++k) {
// ... launch the threads
vector<std::future<double> > values;
for (uint w=0; w<nThreads; ++w) {
values.push_back(std::async(TestFutures));
}
// ... and now read the results
for (uint w=0; w<nThreads; ++w) {
results[w]+= values[w].get();
}
}
}
int main()
{
const uint nTimes=50;
for (uint k=0; k<nTimes; ++k) {
cout << "Cycle: " << k << endl;
DoWork();
}
}
I compile it with gcc 4.7.2 (MinGW 4.7.2) in Qt 5.0.1, Qt Creator 2.6.2. Then I
run it, either in the debugger, or stand alone, release or debug version. If I
monitor the memory usage, it increases monotonically during the execution of
the loops. By increasing the variable nTimes in the main function, I can make
the program allocate an arbitrary amount of memory (I have tried up to 1Gb). I
monitor the memory usage with task manager or procexp.
If I then take the same code and compile it and run it under MS Visual Studio
Express 2012, the memory usage remains stable during the loop. This, I think,
is what you would expect, as the vector of futures should be destroyed after
each k-iteration.
I reported this in the MinGw bug forum and was redirected here.
Just to let you know, I still have the same issue if I substitute the vector of
futures with an array, i.e. this DoWork() routine:
void DoWork()
{
const uint nPoints=50;
const uint nThreads=100;
vector<double> results(nThreads,0);
// For each data point...
for (uint k=0; k<nPoints; ++k) {
// ... launch the threads
array<std::future<double>,nThreads> values;
for (uint w=0; w<nThreads; ++w) {
values[w]=std::async(TestFutures);
}
// ... and now read the results
for (uint w=0; w<nThreads; ++w) {
results[w]+= values[w].get();
}
}
}