22

I was trying to understand the terms Synchronous and Asynchronous communication but i am getting confused a bit. I tried to dig a bit into this but there are still confusions. My questions are as follows:

1.How does the synchronous and asynchronous communication work? also with reference to the above mentioned what are the signals used for asynchronous communication.

2.How does the synchronous and asynchronous process work?

Any example to illustrate this is would be helpful.

Apologies in case this is a very simple question. I am new to programming. Hoping your answers help me. Thanks in Advance!!!!

Community
  • 1
  • 1
Shash
  • 4,160
  • 8
  • 43
  • 67

2 Answers2

100

Calling someone on telephone is synchronos. Communicating with him per mail is asynchronous.


synchronous

When I call you on the phone, I dial your number and WAIT until you pick up. Then you say something, and in the very same moment I listen to you. When you finished, I send you data (talk to you) and in the same moment you receive them (listen to me). At the end of our communication one of us says "END OF TRANSMISSION" (Good Bye), the other says "Acknoledged" (Good Bye) and then both ring off.


asynchronous

I write you a letter. I put it to the postoffice, and it will be sent to you. I the meantime I do NOT WAIT. I do many different other things. Then you receive the letter. You read it while I still do many different other things. Then you write me an answer and send it to me. In all those things I am not involved. At the next day I get a (synchronous) message (a signal) from the system (postman). It (he) says: "Here is a message for you". Alternatively I could poll my inbox every five minutes to check if a new letter is there. Then I pause my other work, receive your letter and read your answer. Then I do something according to this answer. But this are things you will not notice, because you are not involved in what I do with your asynchronous answer.

Hubert Schölnast
  • 8,341
  • 9
  • 39
  • 76
  • 1
    thank you for this, really helped me understanding the difference and which one to use – user1189352 Oct 14 '13 at 23:52
  • Actually, I think this answer is for connection oriented and connectionless communication – lenhhoxung Aug 15 '15 at 13:36
  • I like the analogy, but in asynchronous mode how would I know the difference between you 'A' and 'B' if there was a long string of them. More specifically if I'm transmitting at 9600 Baud each bit should last approximately 104us but not exactly. If I keep sampling at 104us won't I eventually become out of sync? Do I use the STOP and START bits to reset my timer? – Lpaulson Dec 07 '15 at 21:42
  • 1
    @Lpaulson: This has nothing to do with the question. You are talking about synchronization of binary data with a given frequency. But the question is about calling methods and function within a computer language. How Information is encoded and sent is irrelevant for synchronous/asynchronous communication. Talking on phone and writing paper-letters are not just analogies. They are really examples of those kinds of communication. Calling someone on phone IS synchronous communication, but there are not bits that need to be synchronized. – Hubert Schölnast Dec 07 '15 at 22:11
  • 1
    great explanation :) – Sudip Das Nov 18 '16 at 19:10
18

synchronous your code sends a message, calls a function etc. and is blocked until an answer, a return value etc. arrives.

asynchronous your code continues executing after sending a message/calling a function, you usually pass a reference to a callback function that executes when the answer arrives (can happen in an hour, couple of days, years), your main thread continues in the meantime.

kosmičák
  • 1,043
  • 1
  • 17
  • 41