|
-
September 3rd, 2004, 02:18 PM
#1
ReadFile() interferes in WriteFile()
Hello,
I have an multi-threaded application that uses the APIs ReadFile() and WriteFile() to access the serial port. One thread reads periodically the serial port and the other writes upon an event.
What I have found is that when a ReadFile() operation is in progress, the WriteFile() operation waits until the first one completes!!! Even in separated threads...
Does anyone have any idea of how to solve this???
Thanks in advance,
Wagner
-
September 3rd, 2004, 06:13 PM
#2
Re: ReadFile() interferes in WriteFile()
You might try wrapping your read and write calls inside a CriticalSection.....
MSDN Sample
Code:
// Global variable
CRITICAL_SECTION CriticalSection;
void main()
{
...
// Initialize the critical section one time only.
if (!InitializeCriticalSectionAndSpinCount(&CriticalSection, 0x80000400) )
return;
...
// Release resources used by the critical section object.
DeleteCriticalSection(&CriticalSection)
}
DWORD WINAPI ThreadProc( LPVOID lpParameter )
{
...
// Request ownership of the critical section.
EnterCriticalSection(&CriticalSection);
// Access the shared resource.
// Release ownership of the critical section.
LeaveCriticalSection(&CriticalSection);
...
}
Last edited by f1shrman; September 3rd, 2004 at 06:16 PM.
-
September 3rd, 2004, 08:58 PM
#3
Re: ReadFile() interferes in WriteFile()
Originally quoted by wschalch
Does anyone have any idea of how to solve this???
Overlapped IO
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
|