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
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);
...
}
Re: ReadFile() interferes in WriteFile()
Quote:
Originally quoted by wschalch
Does anyone have any idea of how to solve this???
Overlapped IO