From: dmitry.sychov on
Hello,

I've being successful in cancelling lengthy ReadFile/WriteFile (400MB
test file) op
with applying PAGE_NOACCESS flag to the input/output buffer pages via
helper thread.


So every time ReadFile/WriteFile is nicely aborted with
ERROR_INVALID_USER_BUFFER
error code, on write operation the newly created file remains of zero
size(NTFS) on any progress.


I've measure the cancel costs:
it takes about 3.000.000 cpu clock cycles to apply the PAGE_NOACCESS
flag on every 32 page of the whole 400 MB buffer.


it takes about 5.000.000 - 12.000.000 cycles for read/write op to
actually be aborted
- so the word instant applies here.


(on the same system it takes 450.000 cycles for socket() call to
return)


the buffer is allocated with malloc(..) and aligned on page size
boundary.


any there are any hidden probs with such approach?


regards, dmitry sychov

From: dmitry.sychov on

Not hard at all.

CancelIO() waits for completion anyway.

besides some file op could not be asynchronous, like file
writing which results in file extending

regards, dmitry

> Seems a very hard way to achieve what you do.
> If I have lengthy file I/O operations, I usually use asynchronous
> read/write operations (see OVERLAPPED structure in MSDN).
> Thus it is easy to cancel an read/write by calling the "CancelIO()"
> function.
> Additional benefit: you don't need a helper thread to do this.
> Regards,
> Martin