Asynchronous vs synchronous execution

Asynchronous vs synchronous execution

In a computer program, there are many serial data transfer protocols. The protocols for serial data transfer can be grouped into two types: synchronous and asynchronous.

A code is a series of instructions, which are run one at a time in sequential order. During normal code execution, an instruction in one function might call out to another function. At this point, the instructions in the other function begin running and the original code is put aside for a moment.

When the other function is done, it returns to our original code with some return value. Our original code resumes its execution and can do something with that return value. We refer to this as synchronous execution. However, some code operates outside the normal code execution. We refer to this as asynchronous execution.

Synchronous vs Asynchronous

  • Synchronous refers to events and processes that occur simultaneously or have dependencies relating to time or another event that relies on time.

  • The term asynchronous is usually used to describe communications in which data can be transmitted intermittently rather than in a steady stream.

  • Synchronous is an adjective describing objects or events that are coordinated in time. In information technology, the term has several different usages.

  • Asynchronous is an adjective describing objects or events that are not coordinated in time. In information technology, the term has several different usages.

  • A synchronous operation blocks a process until the operation completes.

  • An asynchronous operation is non-blocking and only initiates the operation.

  • Asynchronous message passing allows more parallelism. Since a process does not block, it can do some computation while the message is in transit.

  • In a synchronous system, such parallelism can be achieved by forking a separate process for each concurrent operation, but this approach incurs the cost of extra process management. This cost is typically bearable with lwps but not hwps.

  • An asynchronous operation needs to return a call/transaction id if the application needs to be later notified about the operation.

  • many MySQL drivers used a synchronous approach when executing SQL statements.

  • Any MySQL client that supports the X Protocol can provide asynchronous execution, either using callbacks, Promises, or by explicitly waiting on a specific result at the moment in time when it is actually needed.

  • Using callbacks is a very common way to implement asynchronous operations.

  • In the pseudo-code, using synchronous execution, you’ll have to wait for the call to function return and display the function returns message. There is no way to cancel the picture.

  • Using asynchronous execution, the function returns immediately and shows the message.

Recommended for you