Hi Ross,

>  The read and write
routines should be accessing different memory buffers at all times, and this
seems to be the case when no seek is done.  It all works fine.

This sort of assumption is dangerous when dealing with threads.  :-)

Without knowing what
    InterlockedExchangeAdd(@FBufferSize,Len);
does, but suspecting that this is where the buffer information is updated and stored, then I suspect that this is the source of your problem.

I would suggest that you put the same critical section around this call only in both the read and write routines. This allows both to do most of their work independantly, but forces them to converse before accessing the buffer information.

Someone once explained to me that even if it's a single byte of information that is exchanged, you have to assume that this memory location is undefined in the middle of being updated, and that it could be at just this instant of time that the threads are swapped. Assuming such has always stood me in good stead when writing threaded code.

Cheers,
Chris.

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to