Giter Site home page Giter Site logo

echosample's Issues

to avoid data race

This code will cause data competition

package main

import (
	"fmt"
)

type Fruit struct {
	Name string
}


func main() {
	Race()
}
func Race() (newFruit Fruit) {
	go func() {
		newFruit = Fruit{Name: "Pear"}
	}()
	fmt.Printf("race3:exp:Pear,act:%v", newFruit.Name)
	return
}

//go run --race main.go
out put

PS D:\source\gopath\src\race\gofunc> go run --race main.go
race3:exp:Pear,act:==================
WARNING: DATA RACE
Write at 0x00c00003e1d0 by goroutine 6:
main.Race.func1()
	D:/source/gopath/src/race/gofunc/main.go:17 +0x3f

Previous read at 0x00c00003e1d0 by main goroutine:
runtime.convT2Estring()
	C:/GO/src/runtime/iface.go:332 +0x0
main.Race()
	D:/source/gopath/src/race/gofunc/main.go:19 +0x8e
main.main()
	D:/source/gopath/src/race/gofunc/main.go:13 +0x36

Goroutine 6 (running) created at:
main.Race()
	D:/source/gopath/src/race/gofunc/main.go:16 +0x6c
main.main()
	D:/source/gopath/src/race/gofunc/main.go:13 +0x36
==================
Found 1 data race(s)
exit status 66

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.