views:

39

answers:

1

Anything wrong with this in general?

CallingFunction()
{
   CreatePipe()
   CreateMutex()
   CreateThread( ThreadFunction )

   while(there is data left to send)
   {
      WriteFile(send data in 256 byte chunks)
   }

   WaitForSingleobject() //don't return until ReadThread is done

   return 0;
 }

ThreadFunction()
{
   WaitForSinglObject()

   while(bytesRead != totalBytestoReadFileSize)
   {
      ReadfromPipe(in chunks)
      update bytesRead++
   }

   ReleaseMutex()

   return 0;
 }

Before the calling function ends -

FileSize: 232016
BytesWrittenToPipe: 232016
BytesReadFromPipe: 231946 or 232012 or 231840 -> Why not consistent?

+1  A: 

Expecting us to debug such an issue from pseudo code is not realistic. Use FlushFileBuffers to ensure all data in the pipe is written.

Hans Passant