Tag Archives: go error

How to Solve Go Error: concurrent map iteration and map write

Pure dry goods.

Direct cause: problems caused by concurrent read/write of map. The source of your problem must be among the following reasons.

catalogue

Reason 1: abnormal loading and unlocking

Reason 2: adding unlock code looks normal

Reason 3: incomplete locking

Reason 4: the same lock is not added to the map


Reason 1: abnormal loading and unlocking

The code is not written rigorously, the lock is not unlocked, and a single closed loop is not formed
solution: if a closed loop is formed, there must be a solution

Reason 2: adding unlock code looks normal

In fact, the internal code of the lock is lonely. The map operation is not within the scope of the lock. The (read and write together) or the same map (same address) is used with the external code. The lock does not play a practical role

Solution: transfer the map data without using the old map, generate a new map between locking and unlocking,
transfer the data to the new map (or other data structures), and then return to the new map

Or

Just adjust the code position

Reason 3: incomplete locking

Only the goroutine that writes the map is unlocked, but the goroutine that reads the map is not or only goroutine reading map is unlocked, but goroutine writing is not or unlocked

Reason 4: the same lock is not added to the map

For example: for a map, there are two goroutines for reading the map and two goroutines for writing the map. The four are numbered 1,2,3,4. The first three use mu1 and the last one uses mu2, which will cause the error.

Warm tips:
the same lock can act on multiple maps, but the same map cannot have two locks.

[Go] Testing when solving go test: warning: no tests to run

When executing a specified function of go test, the report: testing: warning: no tests to run

For example go test -v -run Mytest

 

The test file name must be this _test suffix

xxxx_test.go

 

If it is not designated to run by correspondence, then the test function must start with Test

For example, the following file can

package tools

import (
    " fmt " 
    " testing "
)

func TestMytest(t * testing.T) {
    Mytest()
}
func Mytest() {
    m: = make(map[ string ] string )
    m[ " a " ] = " b "

    m2: = make(map[ string ] interface {})
    m2[ " a " ] = " b "
    test(m2)
    a: = " aaa "
    test2(a)
}

func test(t map[ string ] interface {}) {
    fmt.Printf( " %T " , t)
}
func test2(t interface {}) {
    fmt.Printf( " %T " , t)
}

 There are two ways of execution

 

go test -v test_test.go

go test -v -run Mytest

Git prompt error setting certificate verify locations

The git version 2.14.2
Git prompts an error setting for the certificate verify locations error
usually because the location of the SSL certificate was not found

two ways to solve:

1. Reconfigure certificate location
Windows certificates are generally installed in the mingw64/ SSL /certs/ca-bundle. CRT directory
configure certificate location

  git config --system http.sslcainfo  "$gitPath/mingw64/ssl/certs/ca-bundle.crt"

Note: $gitPath is git’s installation directory
 
2. Turn off SSL authentication

 git config --system http.sslcainfo  false