fstream.write()
gets stuck during perform to remove directory. It seems that my HDD is so busy while write and remove at the same time. So how can I avoid this stuck, any timeout parameter for the write()
function?. Below is my procedure code:
#include <fstream>
#include <iostream>
int main()
{
std::ios_base::sync_with_stdio(false);
fstream myfile = std::fstream("sample.txt", std::ios::out | std::ios::binary);
//Start thread remove old data
INT64* paramsInput = new INT64[2];
char* dir = "D:\";
paramsInput[0] = (INT64)dir;
paramsInput[1] = 50; //GB
_beginthreadex(Null, 0, &remove_old_data, (VOID*)paramsInput);
int size = 0;
char* data = NULL;
while (true)
{
data = NULL;
size = getData(data); //data is available every 10 ms
if(size > 0 && data != NULL) //size ~= 30 KB
{
myfile.write(data, size); //write data to file
}
}
}
UINT32 __stdcall remove_old_data(VOID* _pArguments)
{
char* dir = (char*)_pArguments[0];
int freeSpaceThreshold = _pArguments[1];
delete[] _pArguments;
while(true)
{
int curFreeSpace = GetFreeSpace(dir);
if(curFreeSpace < freeSpaceThreshold )
{
//remove old files and directory here
ClearData(dir);//File size is about 10 MB, 40,000 files in dir
}
Sleep(10000);
}
}