M
M
Maksimka2014-08-29 19:15:45
Programming
Maksimka, 2014-08-29 19:15:45

Synchronous and asynchronous code, why is it called that?

I want to ask why the code that is executed sequentially (roughly speaking 1 line of code, 2 lines ... n lines) is called synchronous. At the same time, code that runs out of order is called asynchronous.
After all, "synchronously" ( that is, simultaneously, in parallel ) does not mean "in order", "in turn" .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-09-04
@acupofspirt

And the code itself is not called synchronous, it is called by mistake or for simplification. Synchronous and asynchronous is called only the I / O API, i.e. operations that interrupt the execution of code and require the system to access an external device that does not work synchronously with the central processor. Input-output operations, which are: working with disks, ports, controllers, peripheral devices like keyboard, mouse, touchscreen, various sensors, webcam, network cards, bluetooth and other radio modules, printers, video cards and more. All of them receive a task from the program, and execute it separately, with their own capacities. Then external devices send a signal to the program about the execution status and, possibly, the received data. The program can wait all this time (if it has a synchronous API, i.e. blocking) or do something (if it is asynchronous, i.e. blocking). not blocking). If the program waits, does not proceed to the next action, then this is synchronous I / O, because the process of synchronizing the program with an external device is being carried out. Externally, the device sends an interrupt, which is processed by the operating system and through several layers of drivers it gets into the program, usually in the form of a callback or event. If the program waited, then the API call did not end, it listened all the time when the event about the completion of the I/O operation came, and having received it, the API gives a response and control passes to the next command, which is called synchronization with the peripheral device. If the program did not wait, then the API call ends immediately and does not block the flow of program execution, this is called an asynchronous API, because the synchronization process does not occur explicitly,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question