-
May 28th, 2002, 07:44 PM
#1
Need help in Multithreading
Hi All,
My application runs in Windows 2000 Server. The same application is accessed by different users in different windows session creating new application instance for every user.
I have a problem writing data into a file, if I run two instance using two different user Sessions. See the following code (this is a test loop checking for data loss.)
CLog c;
char str[200]={0};
for(int i=0; i < 18000; i++){
HANDLE hMutex = CreateMutex(NULL, FALSE, "MyProtectedErrorHandling");
sprintf(str, "Line:%d Message:Inside the loop, Handle:0x%x", i, hMutex);
DWORD dwResult = WaitForSingleObject(hMutex, INFINITE);
c.write(str); //Opens file in append mode, writes str and closes\ the file.
ReleaseMutex(hMutex);
CloseHandle(hMutex);
}
The total lines should be 36000. But I am not getting all the data I am writing in to the file. I am missing nearly 10 lines of data. Please tell me whether I am using Mutex properly for handling multiple processes or not. If wrong please suggest other useful ways to do this.
Thanks in advance.
Praveen
-
May 29th, 2002, 04:56 AM
#2
CLog c;
char str[200]={0};
HANDLE hMutex = CreateMutex(NULL, FALSE, "MyProtectedErrorHandling");
for(int i=0; i < 18000; i++){
sprintf(str, "Line:%d Message:Inside the loop, Handle:0x%x", i, hMutex);
DWORD dwResult = WaitForSingleObject(hMutex, INFINITE);
c.write(str); //Opens file in append mode, writes str and closes\ the file.
ReleaseMutex(hMutex);
}
CloseHandle(hMutex);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|