Use Golang to achieve the same functionality as ASIO in boost

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Today, on the subway, it occurred to me that it was possible to use the channel in go to easily implement the asynchronous function in ASIO. In fact, ASIO mainly with the use of function variables to hold the code, and it is because C and C + + do not support the reflection, there is no problem in go, the direct use of reflection can be done. Asynchronous execution in Go can be simple, because Channle is naturally a queue, and we start by specifying the channel buffer (which is better than ASIO, because the size of the buffer can solve the problem of traffic control that cannot be solved by the asynchronous program), The code to be executed is then dropped to the channel, a dedicated goroutine to continuously read the execution instructions in the channel and then process. In fact, this multithreading idea is consistent with the idea of solving concurrency in the Go language design, which is to solve the problem by moving data rather than locking it. Just make sure that a single data is processed in one line thread.

But unfortunately, the go language of the current net package does not support non-blocking, and goroutine itself is a closure, and Golang claims that goroutine consumption is very small, the cost of switching is very small, which seems to achieve a ASIO does not make any sense. So this is just a sudden thought on the way to work, there is no need to achieve.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.