From: Tony Johansson on 11 May 2010 07:45 Hi! In the book I read it says "Asyncronous programming is simply allowing some portion of code to be executed on separate threads" If I check the the Rendezvous model wait-until-done and polling they don't use any separate thread that I can see. The last model which is the callback do use a separate thread. So perhaps is the book is meaning the callback model when the book says Asyncronous programming is simply allowing some prtion of code to be executed on separate threads //Tony
From: Willem van Rumpt on 11 May 2010 07:55 Tony Johansson wrote: > Hi! > > In the book I read it says > "Asyncronous programming is simply allowing some portion of code to be > executed on separate threads" > > If I check the the Rendezvous model wait-until-done and polling they don't > use any separate thread that I can see. > The last model which is the callback do use a separate thread. > > So perhaps is the book is meaning the callback model when the book says > Asyncronous programming is simply allowing some prtion of code to be > executed on separate threads > > > //Tony > > Both use a separate thread *, only in the wait-until-done scenario, you block the main thread until the operation is done, and in the rendez-vous model, you don't block. * Or to be more precise: /can use/. There are some heuristics for specific asynchronous operations that check if it would be faster to complete the operation synchronously. -- Willem van Rumpt
From: Tony Johansson on 11 May 2010 08:09 "Willem van Rumpt" <nothing(a)nowhere.com> skrev i meddelandet news:eULPWDQ8KHA.4604(a)TK2MSFTNGP04.phx.gbl... > Tony Johansson wrote: >> Hi! >> >> In the book I read it says >> "Asyncronous programming is simply allowing some portion of code to be >> executed on separate threads" >> >> If I check the the Rendezvous model wait-until-done and polling they >> don't use any separate thread that I can see. >> The last model which is the callback do use a separate thread. >> >> So perhaps is the book is meaning the callback model when the book says >> Asyncronous programming is simply allowing some prtion of code to be >> executed on separate threads >> >> >> //Tony > > Both use a separate thread *, only in the wait-until-done scenario, you > block the main thread until the operation is done, and in the rendez-vous > model, you don't block. > > * Or to be more precise: /can use/. There are some heuristics for specific > asynchronous operations that check if it would be faster to complete the > operation synchronously. > > -- > Willem van Rumpt No the main thread is not blocked as you say. If I run this program which is using the default main thread I can execute statement in between the BeginRead and the EndRead so that means that the main thread is not blocked. Perhaps I missunderstod you but the main thread is not blocked in this simple example. static void Main() { byte[] buffer = new byte[1000]; string filename = "test.txt"; FileStream fstrm = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 1024, FileOptions.Asynchronous); // IAsyncResult result = fstrm.BeginRead(buffer, 0, buffer.Length, null, null); int numBytes = fstrm.EndRead(result); fstrm.Close(); } .. //Tony
From: Willem van Rumpt on 11 May 2010 08:19 Tony Johansson wrote: > > No the main thread is not blocked as you say. > If I run this program which is using the default main thread I can execute > statement in between the BeginRead and > the EndRead so that means that the main thread is not blocked. > Perhaps I missunderstod you but the main thread is not blocked in this > simple example. > > static void Main() > { > byte[] buffer = new byte[1000]; > string filename = "test.txt"; > FileStream fstrm = new FileStream(filename, FileMode.Open, > FileAccess.Read, > FileShare.Read, 1024, FileOptions.Asynchronous); > // > IAsyncResult result = fstrm.BeginRead(buffer, 0, buffer.Length, null, > null); > int numBytes = fstrm.EndRead(result); > fstrm.Close(); > } > . > //Tony > Assuming the operation hasn't completed when you call EndRead, the main thread *will* block on that statement until operation completion. If it doesn't block, it simply means the operation has completed in the meantime (or was actually executed synchronously). Of course, simply calling BeginRead doesn't block, that's the whole point of asynch operations. -- Willem van Rumpt
|
Pages: 1 Prev: asynchronous programming model with BeginRead...EndRead Next: more about asynchronous calls |