My Dll writes data into a file "Sample.txt".
If the Dll is loaded by two processes, then the Sample.txt will be written by both the processes.
In that case, only the process which writes first into file keeps on writing into it. I couldnt see the second process's data in that Sample.txt. I use Mutex for synchronizing between processes.
My code is as below,
HANDLE MLock = CreateMutex(NULL,FALSE,L"MLock");
WaitForSingleObject(MLock,INFINITE);
ofstream fp;
fp.open("Sample.txt",ios::app);
fp << GetCurrentProcessID();
fp.close();
ReleaseMutex(MLock);
I can see only the first process's ID in the Sample.txt. Only if the first process gets killed the second process data is being written. Where am i going wrong?
Note: This issue occurs only in few machines.