views:

496

answers:

5

1.How to understand asynchronous io in Windows??

2.If I write/read something to the file using asynchronous io :

WriteFile();
ReadFile();
WriteFile();

How many threads does the OS generate to accomplish these task?

Do the 3 task run simultaneously and in multi-threading way or run one after another just with different order?

3.Can I use multithreading and in each thread using a asynchronous io to read or write the same file?

A: 

I guess it depends which operating system you are using. But you shouldnt have to worry about this anyhow, it is transparent and should not affect how you write your code.

Nippysaurus
A: 

If you use the standard read and write in windows, you don't have to care that the system may not write it immediately, unless you are writing on the command-line and are waiting for the user to type some input. The OS is responsible for ensuring that what you write will eventually be written to the hard drive, and will do a much better job that you can do anyway.

If you are working on some weird asynchronous io, then please reformat your question.

tomjen
+1  A: 

To your questions:

How many threads does the OS generate to accomplish these task?

Depends if you are using the windows pools, iocp, etc. Generally you decide.

Do the 3 task run simultaneously and in multi-threading way or run one after another just with different order?

This depends on your architecture. On a single-cored machine, the 3 tasks would run one after another and the order would be os decided. On a multi-cored machine these might run together, depending on how the OS scheduled the threads.

3.Can I use multithreading and in each thread using a asynchronous io to read or write the same file?

That is out of my knowledge so someone else would need to answer that one.

I suggest getting a copy of Windows via C/C++ as that has a very large chapter on Asynchronous IO.

graham.reeds
IOCP recommendation is two threads per core.
Blank Xavier
@Blank..: Are the two threads used to deal with the write/read task orto process the entry in the queue enqueued when the write/read task is over?
Jinx
+1  A: 

1.How to understand asynchronous io in Windows??

Read the Win32 documentation. Search on the web. Don't expect an answer to such a large, broad question here in SO.

2.If I write/read something to the file using asynchronous io :

WriteFile(); ReadFile(); WriteFile();

How many threads does the OS generate to accomplish these task?

I don't think it does. It will re-use existing thread contexts to execute kernel function calls. Basically the OS schedules the work and borrows a thread to do it - which is fine, since the kernel context is always the same.

3.Can I use multithreading and in each thread using a asynchronous io to read or write the same file?

I believe so, yes. I don't know that the order of execution is guaranteed to match the order of submission, in which case you will obtain unpredictable results if you issue concurrent reads/writes on the same byte ranges.

Blank Xavier
A: 

I suggest looking for Jeffery Richter's books on Win32 programming. They are very well-written guides for just this sort of thing. I think he has a newer book(s?) on C#, so watch out that you don't buy the wrong one.

a_mole