In this article, section ‘More Waiting…’, when author talked about synchronize i/o with thread, the 1st example he gives is:
hFile = CreateFile(....,FILE_IO_OVERLAPPED,...);
ReadFile(hFile,...)
< Do some computation.>
WaitForSingleObject(hFile,INFINITE);
I had the impression that both ‘CreateFile’ and ‘ReadFile’ are synchronous APIs, no? Why would a ‘WaitForSingleObject’ needed here? Wouldn’t ‘CreateFile’ and ‘ReadFile’ block until the operation is over and then return?
Then some more confusion coming when author talks about ‘alertable waiting’. What is it, a thread state after WaitForSingleObjectEx()? then why author give:
while (WaitForSingleObject(hObject,TRUE)==WAIT_IO_COMPLETION);
as example instead of
while (WaitForSingleObjectEx(hObject,TRUE)==WAIT_IO_COMPLETION);
?
and should ‘ex’ functions be together like:
hFile = CreateFile(....,FILE_IO_OVERLAPPED,...);
ReadFileEx(hFile,...)
< Do some computation.>
while (WaitForSingleObjectEx(hObject,TRUE)==WAIT_IO_COMPLETION);
Any one can explain a little more?
Thanks,
The document also states following:
The methods are synchronous/asynchronous depending on parameters passed to CreateFile
* should read FILE_FLAG_OVERLAPPED