Click here to Skip to main content
15,921,295 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a difference in CPU usage between Asynchronous and Synchronous reads from a communication port?

I've tried putting the reads in a separate thread but I don't see any difference.
Posted

1 solution

It depends on what you do. Asynchronous read certainly uses a bit more resources. But consider what happens if you use synchronous read. If all you code is sequential with the synchronous read in between, you really save some time. This is typical for some console application.

When you need some UI application, you need to keep UI responsive. As the synchronous operation is blocking, you need do it in some other thread, not in the UI thread. So, you need to spend some CPU time on support of threading and essentially get to the same situation as with asynchronous read.

Now, don't get me wrong: I do not promote asynchronous operations. Just the opposite: I advise anyone to do exactly what I described in the above paragraph: to create additional thread(s). They work just fine, and make the code more straightforward compared to somewhat over-complicated asynchronous operations.

I really think that the аsynchronous flourished when threading APIs were not common place as they are now. Using аsynchronous operations is essentially the same as having an extra thread behind the scene, but without all the control you have with the threads. If you do threading well enough, you should not use asynchronous. I always avoided them; to me, they are just obsolete. Please think about it.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900