What is the difference between synchronous and asynchronous i o




















Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. The mechanisms and implementation details of how to accomplish these tasks vary depending on the type of device handle that is used and the particular needs of the application. In other words, there are usually multiple ways to solve the problem. For more information about thread synchronization, see About Synchronization. Directory handles are almost never used—backup applications are one of the few applications that will typically use them.

In this example, the recommendation would be to allow the completion port routine to be solely responsible for all freeing operations for such resources. Unfortunately it turned out that the overhead of creating a new thread and maintaining multiple connections was so huge that the application was not working effectively at all.

To prevent creating a new thread whenever they wanted to put something into the database usually hundreds times per second they eventually created a pool of threads. But with a growing number of parallel requests, the database slowed down and each thread had to wait a long time before it could finish its work. It turned out that this application required threads in the pool to be able to queue all requests.

The application could not run on Windows platform because this operating system could not handle such an uncommon number of threads. Finally, the application was run on Solaris platform because only this operating system was capable of running such a poorly written code. I suspect that in this situation most programmers would blame Windows for such a low capacity for maintaining threads but, frankly speaking, this is it is not Bill G.

It is not normal to create such a huge amount of threads in one application. The reason for it is the cost of the so-called context switching. In order to switch between threads, your operating system needs to replace values of multiple processor registers and part of its memory.

Context switching is normally not very costly but it needs to take place so frequently that a user experiences the illusion of parallel processing. If you create too many threads, this forces the operating system to switch context frequently and therefore to waste a lot of it processing power. I used to work with phone cards from Dialogic company. Their documentation recommends to use their API in asynchronous mode because creation of for example threads needed for the synchronous mode is way too much.

Further recommendations state that the synchronous mode was introduced only as a framework for easy tests for example as a demo for clients. In this situation you wan wonder — what are the consequences of using threads? Nothing good can come out of that. If threads and synchronous mode are not good for handling multiple parallel IO operations, then what is? It turns out that much more effective is using asynchronous operations in one single thread. Synchronous operations are very easy to understand.

David Schwartz David Schwartz k 17 17 gold badges silver badges bronze badges. Awesome answer! Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile. Related



0コメント

  • 1000 / 1000