Synchronous VS Asynchronous Operations

Synchronous VS Asynchronous Operations

One of the concepts that I recognized that lots of people get it wrong is the difference between synchronous and Asynchronous operations and before stating the difference between both of them lets get these points straight forward.

1-Sync and Async have nothing to do with your functions being being blocking or non blocking you could have a function that performs Asynchronous blocking operation like erasing a sector from the flash memory.

2-Sync and Async have nothing to with Multi-Threading Programing so performing Asynchronous operations is abstracted from the architectural design you adapt in your code you could perform Async operations in many design paradigm you could use.

Keeping the above concepts in your mind lets state the difference between Sync and Async operations.

Sync Operations is any type of operations a function will perform till the end result of the desired operation is obtained, for example a function that writes a buffer to the flash memory if the operation of writing data is a synchronous operation this function won't finish execution and return from its context till the whole buffer is written into the memory and the final result of the writing operation is returned immediately to the user after the functions has been called.

On the other hand Asynchronous Operations is any type of operations a function will start or perform that doesn't have to be finished after the function return from its context with a promise from the function to call back the calling context using a callback function after the whole operation desired result is finished.

using the example of writing a buffer into the flash if this operation is Async one so the writing of the flash will be divided into sub smaller operations the operation won't take place at one time so if the operation is writing 1KByte into flash it could divide the writing operations into 256 blocks "assuming this is the page size of the flash" and the functions would write 256Byte each time it is called till the whole buffer is written and then a callback for writing is finished should be asserted to inform the application that writing operation has finished. the function that performs the write operation could be called in a simple super loop architecture or from a scheduler or even from an interrupt where the processing of the operation could continue.

Now you know the difference between Async and Sync operations but you should ask yourself why would I need to use Async operations? the answer is that using Aync operations would shorten the time needed to perform long operations so your application could do other stuff at the same time without the headache of being stuck waiting for the whole operation to finish to continue executing your application. 

Islam Abdeen

Senior C++ Software Engineer | Adaptive Autosar Expert | Embedded Linux | Yocto | AOSP | CMake | GTest/Mock | Modern C++)

3 年

Omar Ehab Do you have use case for Async blocking? Why do we need to use blocking with Async?

要查看或添加评论,请登录

Omar Ehab的更多文章

  • Introduction to Cache Memory

    Introduction to Cache Memory

    Microcontrollers are the heart of every embedded system and in the last decades we have seen an increase in their…

    3 条评论
  • CPU Utilization in Embedded systems

    CPU Utilization in Embedded systems

    An important metric that give an insight about the system performance is the CPU load or utilization. In the following…

    30 条评论
  • Flash Memory in Embedded Systems

    Flash Memory in Embedded Systems

    A trivial mistake that lots of beginners in embedded systems do when they get introduced to Flash and EEPROM is they…

    2 条评论
  • Secure Firmware flashing using firmware signing

    Secure Firmware flashing using firmware signing

    The ability to flash a new Firmware to your embedded target using a boot-loader is essential but did you think what if…

    3 条评论
  • Access Synchronization

    Access Synchronization

    Writing Embedded software you will usually encounter the situation where you have to synchronize your tasks either for…

    3 条评论
  • Thread safe and Non-Thread safe Vs Re entrant and Non-Re entrant functions

    Thread safe and Non-Thread safe Vs Re entrant and Non-Re entrant functions

    Multi threading environment could be chaotic if careful design consideration is not taken and one of the most famous…

    4 条评论
  • Interrupt Latency

    Interrupt Latency

    It is known that we use interrupts in embedded software in order to serve asynchronous event almost immediately.so the…

    7 条评论
  • Scheduling analysis and testing using Rate monotonic algorithm with time demand analysis.

    Scheduling analysis and testing using Rate monotonic algorithm with time demand analysis.

    Following up with the article i published before about scheduling and multitasking.In this short tutorial we will see…

  • Functions VS ISR

    Functions VS ISR

    Have you ever thought why interrupt service routines(ISR) in some tool-chains is written in a special format that is…

    2 条评论
  • Introduction to multitasking and scheduling in Embedded systems

    Introduction to multitasking and scheduling in Embedded systems

    This will be a short introduction into multitasking in embedded systems. First what is multitasking? Multitasking is…

    3 条评论

社区洞察

其他会员也浏览了