rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.04k stars 572 forks source link

data race #87

Closed stephencheng closed 6 years ago

stephencheng commented 6 years ago

Firstly, I'd say I am amazed by this project. It's great work there.

I was using termui and now entirely stuck with lots of effort dealing with the user interaction and found it is a dead end. And I am lucky to just land here to find a rescue.

I am not sure if a data race warning should be concerned at all as I just run it for the very basic example of a box, see below

I am considering using tview to deal with a timely refresh to get data for each tab(page), would it be even possible that I can use go route to deal with the backend task(to get some server end data) for each page in the background?

Thank you

Ξ demos/box git:(master) ▶ go run -race main.go

WARNING: DATA RACE Write at 0x00c420062f18 by main goroutine: gitlab.com/cmartoo/goexample/vendor/github.com/gdamore/tcell.(tScreen).Fini() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/vendor/github.com/gdamore/tcell/tscreen.go:403 +0x34b gitlab.com/cmartoo/goexample/vendor/github.com/rivo/tview.(Application).Stop() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/vendor/github.com/rivo/tview/application.go:179 +0xbe gitlab.com/cmartoo/goexample/vendor/github.com/rivo/tview.(Application).Run() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/vendor/github.com/rivo/tview/application.go:148 +0x51e main.main() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/examples/libs/goui/tview/demos/box/main.go:10 +0x2af Previous read at 0x00c420062f18 by goroutine 9: gitlab.com/cmartoo/goexample/vendor/github.com/gdamore/tcell.(tScreen).mainLoop() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/vendor/github.com/gdamore/tcell/tscreen.go:1253 +0xb0 Goroutine 9 (finished) created at: gitlab.com/cmartoo/goexample/vendor/github.com/gdamore/tcell.(tScreen).Init() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/vendor/github.com/gdamore/tcell/tscreen.go:175 +0xab5 gitlab.com/cmartoo/goexample/vendor/github.com/rivo/tview.(Application).Run() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/vendor/github.com/rivo/tview/application.go:85 +0x12d main.main() /Users/stephencheng/data/workspace/golangworkspace/gocmartoo/src/gitlab.com/cmartoo/goexample/examples/libs/goui/tview/demos/box/main.go:10 +0x2af

Found 1 data race(s) exit status 66

rivo commented 6 years ago

It looks like this race condition is happening in tcell. You may want to open an issue there.

Generally, you should be able to use goroutines in a tview project. For example, if you write text to a TextView, you can do that asynchronously. And many of the functions in Application are thread-safe, too.

If you're setting attributes of a primitive concurrently in multiple goroutines, e.g. List.SetCurrentItem() or Table.SetCell(), you may have to synchronize those updates yourself. I guess I couldn't think of any real-life cases where you would need these functions to be thread-safe. But if you run into trouble with these in your project, let me know and I'll see if I can find a solution.

stephencheng commented 6 years ago

Thanks for replying