views:

34

answers:

1

In the following, it is said that an I/O handle must be associated with the thread pool but i could not find where in the given example an handle is associated with the thread. Which function or code helps to bind the file handle in that example?

Using asynchronous I/O completion events, a thread from the thread pool processes data only when the data is received, and once the data has been processed, the thread returns to the thread pool. To make an asynchronous I/O call, an operating-system I/O handle must be associated with the thread pool and a callback method must be specified. When the I/O operation completes, a thread from the thread pool invokes the callback method. http://msdn.microsoft.com/en-us/library/aa720215(VS.71).aspx

A: 

In the C# example on that page, in ProcessImagesInBulk, you'll see the following:

  AsyncCallback readImageCallback = new AsyncCallback(ReadInImageCallback);
  for(int i=0; i<numImages; i++)
  {
     ...
     fs.BeginRead(state.pixels, 0, numPixels, readImageCallback, state);
  }

In this case, the FileStream.BeginRead call is what is starting the asynchronous I/O. The callback parameter (here: readImageCallback) is what gets invoked when the read completes.

The binding of the handle to the thread is abstracted away behind the library code. I'm not sure why that article even mentions it. In the case of .NET, the callback is invoked on the .NET ThreadPool, which is what associates a thread with the I/O completion.

Chris Schmich