How is parallel programming different with respect to Asynchronous programming?
I know async programming is used to do work in background threads/workers or waiting for something to finish like I/O.
*Can task(s) in parallel be also task(s) in async?
*Can task(s) in async b开发者_如何学JAVAe done in parallel?
Bit confusing for me.
Any examples for the above?
Multi threaded, Multi process and asynchronous programming are all concurrency techniques whereby you can get more than one thing done at a time in a single program. If you have just a single processor/machine, none of these are truly "parallel". They all just pipeline the execution of some code so that you "feel" like they're all executing together.
The first two rely on the CPU switching tasks for you. You simply tell the computer somehow that these are the things you want done and then let it decide how to allocate time and other resources to the various tasks. We'll gloss over the differences between threads and processes here.
Asynchronous programming means that your application controls the switching of these tasks you want done. An crude example is when there are 2 I/O channels you want to read/write to. Your application can sort of send data to 1 till 2 has data available on it. When it does, it will read out the data from 2 and then resume sending to 1 and then switch to sending data to 2. The idea is that you wait till there are some events that need to be serviced and then switch between events as per availability and need. In some sense, you're manually doing the process scheduling with these kinds of apps. One advantage is that the system overhead associated with multiple processes/threads is not there. Many asynchronous routines rely on the select system call.
精彩评论