Various pits in the Golang (continuous update)

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

The following summary is a recent Golang development encountered, and the internet collected on the pit, will continue to update:

  1. The string is not \x0 judged by the end

  2. No lock queue is only in single core, multicore also need lock, need to dispatch between threads

  3. The formatted time string can only be used 2006 01 02 15 04 05 (the time origin) and is time/format.go written dead:

    2006-01-02T15:04:05Z07:00

    In fact, this is meaningful, and each field corresponds exactly to:

    1 2 3 4 5 6 7月 日 时 分 秒 年 时区
  4. When multiple channel is in the ready state, the activation channel is random and cannot be judged in order

  5. os.exit(1)After execution, defer is not useful.

  6. Goroutine The goroutine switch occurs only if the non-blocking IO call is blocked, if it is a system call:

    Golang will be directly 启动内核级线程 , to realize the asynchronous ... So avoid a lot of booting system calls ...

  7. Memory leaks in a pit If your code appears like this, congratulations, you're already in the pit.

    func somefunc() {    for {        // ...        defer something.Cleanup()    }}

    The reason is that the defer here have no chance of being executed. The simple solution is to put the logic here in one way.

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.