Asynchronous vs synchronous execution, what does i

2018-12-31 01:16发布

What is the difference between asynchronous and synchronous execution?

21条回答
步步皆殇っ
2楼-- · 2018-12-31 01:35

Synchronous execution means the execution happens in a single series. A->B->C->D. If you are calling those routines, A will run, then finish, then B will start, then finish, then C will start, etc.

With Asynchronous execution, you begin a routine, and let it run in the background while you start your next, then at some point, say "wait for this to finish". It's more like:

Start A->B->C->D->Wait for A to finish

The advantage is that you can execute B, C, and or D while A is still running (in the background, on a separate thread), so you can take better advantage of your resources and have fewer "hangs" or "waits".

查看更多
余欢
3楼-- · 2018-12-31 01:39

I'll try to explain as simply as I can so you'll (hopefully) remember:

Synchronous Execution

My boss is a busy man. He tells me to write the code. I tell him: Fine. I get started and he's watching me like a vulture, standing behind me, off my shoulder. I'm like "Dude, WTF: why don't you go and do something while I finish this?"

he's like: "No, I'm waiting right here until you finish." This is synchronous.

Asynchronous Execution

The boss tells me to do it, and rather than waiting right there for my work, the boss goes off and does other tasks. When I finish my job I simply report to my boss and say: "I'm DONE!" This is Asynchronous Execution.

It's really that simple! Hope it helps.

(Take my advice: NEVER work with the boss behind you.)

查看更多
柔情千种
4楼-- · 2018-12-31 01:39

I think this is bit round-about explanation but still it clarifies using real life example.

Small Example:

Let's say playing an audio involves three steps:

  1. Getting the compressed song from harddisk
  2. Decompress the audio.
  3. Play the uncompressed audio.

If your audio player does step 1,2,3 sequentially for every song then it is synchronous. You will have to wait for some time to hear the song till the song actually gets fetched and decompressed.

If your audio player does step 1,2,3 independent of each other, then it is asynchronous. ie. While playing audio 1 ( step 3), if it fetches audio 3 from harddisk in parallel (step 1) and it decompresses the audio 2 in parallel. (step 2 ) You will end up in hearing the song without waiting much for fetch and decompress.

查看更多
旧时光的记忆
5楼-- · 2018-12-31 01:41

Synchronous basically means that you can only execute one thing at a time. Asynchronous means that you can execute multiple things at a time and you don't have to finish executing the current thing in order to move on to next one.

查看更多
唯独是你
6楼-- · 2018-12-31 01:42

You are confusing Synchronous with Parallel vs Series. Synchronous mean all at the same time. Syncronized means related to each othere which can mean in series or at a fixed interval. While the program is doing all, it it running in series. Get a dictionary...this is why we have unsweet tea. You have tea or sweetened tea.

查看更多
何处买醉
7楼-- · 2018-12-31 01:42

Yes synchronous means at the same time, literally, it means doing work all together. multiple human/objects in the world can do multiple things at the same time but if we look at computer, it says synchronous means where the processes work together that means the processes are dependent on the return of one another and that's why they get executed one after another in proper sequence. Whereas asynchronous means where processes don't work together, they may work at the same time(if are on multithread), but work independently.

查看更多
登录 后发表回答