I want to set a value with the index of the slice. I don't really care if 
there are multiple goroutines cover the value with each other, because the 
value is same.

Can i just ignore this DataRace Warning? I don't know if this will cause 
panic.

*Here's my example:*
I defined a structure with slice, and a Add() function for it. sample like 
this:
```go
package test_slice

type SliceObj struct {
    set []uint
}

func New(length int64) *SliceObj {
    return &SliceObj{
        set: make([]uint, length),
    }
}

func (b *SliceObj) Add(i uint) {
    b.set[i] = i
}
```

And then i make a main file to test it, like this:
```go
package main

import (
    "time"

    "test_slice"
)

func main() {
    s := test_slice.New(1000000)
    go func() {
        s.Add(10)
    }()
    s.Add(10)

    time.Sleep(3 * time.Second)
}
```

*And data race is detected:*
*(*I know the reason of this warning, but I don't know if I can ignore it*)*
==================
WARNING: DATA RACE
Write at 0x00c000180050 by goroutine 18:
  test_slice.(*SliceObj).Add()
      test_slice.go:27 +0x68
  main.main.func1()
      test.go:25 +0x36

Previous write at 0x00c000180050 by main goroutine:
  test_slice.(*SliceObj).Add()
      test_slice.go:27 +0xfd
  main.main()
      test.go:27 +0xcb

Goroutine 18 (running) created at:
  main.main()
      test.go:24 +0xca
==================
Found 1 data race(s)
exit status 66

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0b0b0178-987f-42bc-b8ef-47516764ffcen%40googlegroups.com.

Reply via email to