简体   繁体   中英

fclose does not close audio file

I have the following C++ code to write shorts to a headerless audio file:

vector<short>nShrtDecoded;
nShrtDecoded.resize(iCountDecodedShorts);//-1

//Then I fill the vector of short with some audio. I didn't write that length code here. I think it doesn't matter anyway HOW exactley I fill this vector of shorts

FILE* outfile = fopen("d:\\!wavs\\weg.raw", "wb");
fwrite(&nShrtDecoded[0], sizeof(short), nShrtDecoded.size(), outfile);
fclose(outfile);

I run this code in Debug mode, and I have set a breakpoint in the line following the "fclose(outfile)" line.

As soon as this breakpoint is hit, I try to delete this file using the Windows Explorer. This should work as the file has already been closed using "fclose".

When I try to delete the file "d:\\!wavs\\weg.raw", Windows tells me "File in use: The action could not be completed as the file is in use by a different program":

在此处输入图片说明

As I didn't think that this is true, I fired up LockHunter. LockHunter told me the following:

在此处输入图片说明

Does anybody know what this strange behaviour could be caused by?

I found the culprit:

I run this in a parallel_for.

That explains everything. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM