zhanglong2005 / plotinum

Automatically exported from code.google.com/p/plotinum
MIT License
0 stars 0 forks source link

vg.getFont is not thread safe #140

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The "previous write" frequently gets corrupted, but here is my stack trace

WARNING: DATA RACE
Write by goroutine 56:
  runtime.mapassign1()
      /usr/local/go/src/pkg/runtime/hashmap.c:1134 +0x0
  code.google.com/p/plotinum/vg.getFont()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/vg/font.go:197 +0x442
  code.google.com/p/plotinum/vg.MakeFont()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/vg/font.go:100 +0x7d
  code.google.com/p/plotinum/plot.New()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/plot/plot.go:88 +0x5e
  github.com/btracey/ransuq.makeComparisons()
      /Users/brendan/Documents/mygo/src/github.com/btracey/ransuq/postprocess.go:106 +0xf50
  github.com/btracey/ransuq.func·005()
      /Users/brendan/Documents/mygo/src/github.com/btracey/ransuq/postprocess.go:219 +0x6fa

Previous write by goroutine 57:
  [failed to restore the stack]

The problem is that two different threads can read from and write to 
loadedFonts at the same time. There might be a more elegant solution, but an 
easy solution is to use an RWMutex. The following edit fixed my data race 
http://play.golang.org/p/KQOk20Ts6v

Original issue reported on code.google.com by tracey.b...@gmail.com on 1 Apr 2014 at 9:14

GoogleCodeExporter commented 9 years ago
Sorry, here is a better example program
http://play.golang.org/p/F-5hv0LPhn

brendan:~/Documents/mygo/src$ go run -race Testing/plotinumrace/main.go 

==================
WARNING: DATA RACE
Write by goroutine 3:
  runtime.mapassign1()
      /usr/local/go/src/pkg/runtime/hashmap.c:1134 +0x0
  code.google.com/p/plotinum/vg.getFont()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/vg/font.go:204 +0x474
  code.google.com/p/plotinum/vg.MakeFont()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/vg/font.go:101 +0x7d
  code.google.com/p/plotinum/plot.New()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/plot/plot.go:88 +0x5e
  main.func·001()
      /Users/brendan/Documents/mygo/src/Testing/plotinumrace/main.go:13 +0x34

Previous write by goroutine 4:
  runtime.mapassign1()
      /usr/local/go/src/pkg/runtime/hashmap.c:1134 +0x0
  code.google.com/p/plotinum/vg.getFont()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/vg/font.go:204 +0x474
  code.google.com/p/plotinum/vg.MakeFont()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/vg/font.go:101 +0x7d
  code.google.com/p/plotinum/plot.New()
      /Users/brendan/Documents/mygo/src/code.google.com/p/plotinum/plot/plot.go:88 +0x5e
  main.func·002()
      /Users/brendan/Documents/mygo/src/Testing/plotinumrace/main.go:21 +0x34

Goroutine 3 (running) created at:
  main.main()
      /Users/brendan/Documents/mygo/src/Testing/plotinumrace/main.go:19 +0x10e

Goroutine 4 (finished) created at:
  main.main()
      /Users/brendan/Documents/mygo/src/Testing/plotinumrace/main.go:27 +0x161
==================
Found 1 data race(s)
exit status 66

Original comment by tracey.b...@gmail.com on 1 Apr 2014 at 9:22

GoogleCodeExporter commented 9 years ago

Original comment by burns.ethan@gmail.com on 1 Apr 2014 at 10:20

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 4cda9b60a170.

Original comment by burns.ethan@gmail.com on 5 Apr 2014 at 2:23