The function async leaks memory on Windows - c++11

In an application of mine, I introduced a memory leak when I began to use std::async. After examining the problem with the tool Dr. memory, I found out that std::async leaks memory very often.
I made a quick test that reproduces the problem:
#include <Windows.h>
#include <algorithm>
#include <future>
using namespace std;
void testMethod()
{
for (int i = 0; i < 4; i++)
Sleep(10);
}
int main()
{
for (int i = 0; i < 100; i++)
{
auto result = async(launch::async, testMethod);
result.wait();
}
return 1;
}
How is it possible that the code above will leak memory on Windows? The problem does not occur on Linux. Dr. memory will produce the following log:
Error #1: REACHABLE LEAK 40 direct bytes 0x007badb8-0x007bade0 + 0 indirect bytes
# 0 replace_operator_new_nomatch [d:\drmemory_package\common\alloc_replace.c:2732]
# 1 MSVCR120D.dll!Concurrency::details::SubAllocator::Alloc [f:\dd\vctools\crt\crtw32\concrt\suballocator.cpp:201]
# 2 MSVCR120D.dll!Concurrency::details::ExternalContextBase::Alloc [f:\dd\vctools\crt\crtw32\concrt\externalcontextbase.cpp:238]
# 3 MSVCR120D.dll!Concurrency::Alloc [f:\dd\vctools\crt\crtw32\concrt\suballocator.cpp:34]
# 4 Concurrency::details::_AllocBase::operator new [c:\program files (x86)\microsoft visual studio 12.0\vc\include\concrt.h:298]
# 5 Concurrency::task<>::_TaskInitWithFunctor<> [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:3982]
# 6 Concurrency::task<>::_TaskInitMaybeFunctor<> [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:4551]
# 7 Concurrency::task<>::task<><> [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:4198]
# 8 Concurrency::create_task<> [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:4673]
# 9 std::_Task_async_state<>::_Task_async_state<><> [c:\program files (x86)\microsoft visual studio 12.0\vc\include\future:906]
#10 std::_Get_associated_state<> [c:\program files (x86)\microsoft visual studio 12.0\vc\include\future:1859]
#11 std::_Async<>

Related

VISUAL STUDIO can't find the file specified

I wrote this C code
#include <stdio.h>
int main()
{
int a;
scanf("%d", &a);
printf("%d\n", a);
getchar();
return 10;
}
However I am getting this error shown in image.
What is the problem here ?
EDIT1:
I have windows 7 x64 and running VS 15.
Seems there has been similar problem before this might be helpfull.
Visual Studio debugger error: Unable to start program Specified file cannot be found
Go to the specific file location from the error open the program from there. Build it first then try to debug it again.

'iostream': No such file or directory [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Installation of Visual Studio 2010 (any edition) installs only 2 files in the C++ headers directory
I am so desperate Right now its not funny I have searched the entire internet for the answer and its not working.... i have installed and reinstalled visual studio 2010 pro at least 4 times and it doesnt fix anything..... heres my problem
I try to make a simple Hello world project and boom it fails saying this..
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World.." << endl;
return 0;
}
1>------ Build started: Project: ds, Configuration: Debug Win32 ------
1>Build started 1/21/2013 12:31:36 PM.
1>InitializeBuildStatus:
1> Touching "Debug\ds.unsuccessfulbuild".
1>ClCompile:
1> d.cpp
1>c:\users\dj\documents\visual studio 2010\projects\ds\ds\d.cpp(1): fatal error C1083:
Cannot open include file: 'iostream': No such file or directory
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.32
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
my include folder in VC only has these names
ammintrin
omp
pgobootrun
srv
wmiatlprov
Im not to great with this so if ur gonna answer can you put it noob terms:)
Thank you in advance..
When you choose console aplication check the option: include precompiled header, most likely you created an empty project in which case you must manualy add the path to iostream file
in .vcxproj directory includes you should have:
Include Directories $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;
and
Library
$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib
if you have these and stdafx.h include in cpp but still no path to iostream you should check PATH environment variable not to be broken or any of the variables $(VCInstallDir) $(WindowsSdkDir) $(FrameworkSDKDir)

Microsoft MPI doesn't run

I'm trying out Microsoft's implementation of MPI. I installed the CCP sdk from here:
http://www.microsoft.com/en-us/download/details.aspx?id=239
And then in my project settings I added the include folder, the lib folder and mentioned msmpi.lib.
With the remaining settings as-is, I build the program and then in the command prompt I proceed to run the program, but nothing happens after I start it up.
Here's the code (It's supposed to display the id numbers for each thread):
#include "stdafx.h"
#include "mpi.h"
#include <stdio.h>
//Commands in cmd prompt
//cd "C:\Program Files\Microsoft Compute Cluster Pack\Bin"
//mpiexec.exe -n 2 "C:\Users\MyNameHere\Documents\Visual Studio 2012\Projects\tspMpi\Debug\tspMpi.exe"
int main(int argc, char* argv[])
{
int nTasks = 0, rank = 0;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&nTasks);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
printf ("Number of threads = %d, My rank = %d\n", nTasks, rank);
return 0;
MPI_Finalize();
}
As soon as I run mpiexec.exe (the commands are in the comments) the program just does nothing, until I press Ctrl-C. Does anyone know what I'm doing wrong? There are no errors when I build the program, and if I run it from visual studio, it acts as if there was only one process started up.
I didn't find SDK useful at all, here are my steps to enable MPI cluster debugging in VS 2010 (VC10):
step 1. Install MS-MPI: http://www.microsoft.com/en-us/download/details.aspx?id=36045 (x64 only), this creates
C:\Program Files\Microsoft HPC Pack 2012\Inc
C:\Program Files\Microsoft HPC Pack 2012\Lib\amd64
C:\Program Files\Microsoft HPC Pack 2012\Lib\i386
step 2. Download example: http://msdn.microsoft.com/en-us/library/ee441265(v=vs.100).aspx#BKMK_debugMany
step 3. Debugging setting: Right click on the Startup Project > Properties > Debugging
Debugger to launch, change "Local Windows Debugger" to "MPI Cluster Debugger"
Run Environment, change "localhost/1" to "localhost/4"
Right click on Visudal Studio Toolbar area to check "Debug Location", now you can switch Process and its Threads in the Debug Location toolbar, have fun!

compiler error in MS visual studio 2010

I am compiling my C source code in MS visual Studio C++ 2010.I am getting following following errors while building. What can be the reasons for it?
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(18): error C2061: syntax error : identifier 'suseconds_t'
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(19): error C2059: syntax error : '}'
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(37): error C2079: 'it_interval' uses undefined struct 'timeval'
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(38): error C2079: 'it_value' uses undefined struct 'timeval'
[EDIT ]
Following is the code in my program:
#ifndef _DWORD_DEFINED
#define _DWORD_DEFINED
typedef unsigned long DWORD;
#endif
int getTime(struct timeval * tp, void * tzp)
{
DWORD milliseconds;
milliseconds = timeGetTime();
tp->tv_sec = milliseconds / 1000;
tp->tv_usec = (milliseconds % 1000) * 1000;
return 0;
}
Without any code, all I can say is this:
The first error cause is this.
The second error cause is this.
The third and fourth error cause is this.
Edit: After the OP's edit, the errors are more than obvious. Look at the struct timeval.
Where is it's definition? You access members of that struct and still you there is no visible definition of the struct.

Is there a Windows equivalent of EDQUOT?

I'm porting some C++ code from UNIX to Windows which detects the occurrence of the EDQUOT error, which indicates that there was an unsuccessful attempt to exceed the current user's disk quota. Visual Studio's <errno.h> doesn't have an EDQUOT, although I know that Windows has disk quota functionality. Visual Studio's <errno.h> does have an ENOSPC, which might be how the CRT expresses what UNIX would express as EDQUOT. Can anybody confirm or deny this theory? And if this isn't the way to handle this, what is?
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\WinSock.h
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\WinSock.h
#if 0
#define EDQUOT WSAEDQUOT
#endif
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\WinError.h
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\WinError.h
//
// MessageId: WSAEDQUOT
//
// MessageText:
//
// Ran out of disk quota.
//
#define WSAEDQUOT 10069L

Resources