This is the 8th day of my participation in the August More Text Challenge. For details, see:August is more challenging

In my column:Let’s Golang

As we all know, the greatest strength of the Go language is the high concurrency features it supports. Let’s first look at some of the theoretical foundations of Go concurrency: synchronous asynchrony, asynchronous callbacks. By the way, I also introduce the difference between process, thread and coroutine.

Process, thread, coroutine difference

  • Writing code, listening to music, and chatting at the same time is process concurrency.
  • A process can run several threads. For example, thunderbolt download a file into multiple chunks, and then multi-threaded download.
  • Coroutines are actually called tasklets, and they have a much lower resource overhead than threads.

Synchronous asynchrony and asynchronous callback

  • Concurrent execution of multiple events is asynchronous

  • The sequential execution of multiple events is synchronous

  • An event that has not been able to retrieve resources to continue execution is blocked. If it is serial, the previous event has not been executed, and the next event has to wait forever

  • What is the asynchronous callback mechanism?

    In layman’s terms, if you and your boss work at the same time, you type code and write documents, and he drinks tea and goes to the club.

    You’re both doing your job at the same time, so it’s asynchronous, and then when you’re done, you have to report to your boss, and you have a conversation with your boss. Don’t call your boss until you’re done. The boss will increase or decrease your bonus according to your performance.

    So the boss doesn’t have to wait for you to finish your hard work and then go to tea and the club.

    This is an asynchronous callback!

  • Advantages and disadvantages of asynchrony:

    • Advantages:

      1. Fast and efficient
      2. There is no strict sequence
      3. Asynchrony eliminates the need to give the caller the final result immediately, and allows more operations to be performed before giving the caller the final result.
      4. Enhance system robustness.
    • Disadvantages:

      1. Callback hell is easy to form when using callback functions
      2. Difficult to develop
      3. The amount of concurrency is not easy to control and can consume too many resources.