Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous and Synchronous Terms

I'm confused by the term asynchronous when related to programming. It seems to mean the opposite in programming terms as what it is defined as in the dictionary. For example, the word synchronous means:

  1. occurring at the same time; coinciding in time; contemporaneous; simultaneous.

  2. going on at the same rate and exactly together; recurring together.

Yet, Wikipedia says:

"In programming, asynchronous events are those occurring independently of the main program flow. Asynchronous actions are actions executed in a non-blocking scheme, allowing the main program flow to continue processing."

Wouldn't something that is "non-blocking" and that allows "the main program flow to continue processing," be synchronized or "occurring at the same time"? It seems like the term synchronous suggests "non-blocking" and asynchronous, "blocking." Why do the terms appear to be used in reverse when related to programming, or does it have something to do with lower-level computing that I don't understand?

When I use an synchronous AJAX call, I do the following...

$.ajax({   url: somefile.php,   async: false,   success: {     ...code that gets run on success...   } });  ...code that gets run after the ajax-success code runs... 

With this, it actually waits for a response before running the rest of the script, it's a blocking action. Then why is this termed synchronous, when it's not synchronized with any other process, but actually the opposite?

like image 781
Allen Avatar asked Aug 20 '11 13:08

Allen


People also ask

What means synchronous and asynchronous?

Synchronous = happens at the same time. Asynchronous = doesn't happen at the same time. With synchronous learning, participants can receive immediate feedback. With asynchronous learning, the participants can learn at their own pace.

What is difference between synchronous and asynchronous classes?

Synchronous classes run in real time, with students and instructors attending together from different locations. Asynchronous classes run on a more relaxed schedule, with students accessing class materials during different hours and from different locations.

What is called asynchronous?

What does asynchronous mean? More specifically, asynchronous describes the relationship between two or more events/objects that do interact within the same system but do not occur at predetermined intervals and do not necessarily rely on each other's existence to function.

What is asynchronous example?

In a nutshell, asynchronous communication is any communication that does not take place in real-time. Emails, forum comments, corporate intranet, and even Asana or Trello boards serve as examples of asynchronous communication we deal with every day.


2 Answers

Indeed, it's one of these cases, where original meaning of the word was subverted and means something different than in popular usage.

'Synchronisation' in telecommunication means that receiver signals whenever it is ready to receive messages, and only after this signal the transmitter will start transmitting. When the transmitter is done with the message, it will signal it has finished, so that receiver can now process the received message and do whatever it is supposed to be doing next.

This is of course a simplification and a very broad one, but it should give you the feeling of from where the meaning of '(a)synchronous' comes in JS.

So synchronous request in JS is actually synchronised with the main flow of the program. The program sends request to server ('I'm ready to receive') and waits for message. Message from the server will have a well defined end ('the message ends here - do your job'). When it is received, JS knows it can continue with execution of the program..

like image 124
Mchl Avatar answered Sep 21 '22 01:09

Mchl


synchronous:- when each task connected and depend on the previous task

asynchronous:- each task independent from others.

like image 33
Chamika Sandamal Avatar answered Sep 22 '22 01:09

Chamika Sandamal