diff --git a/tscreen.go b/tscreen.go
index <HASH>..<HASH> 100644
--- a/tscreen.go
+++ b/tscreen.go
@@ -398,9 +398,12 @@ func (t *tScreen) Fini() {
 	t.clear = false
 	t.fini = true
 
-	if t.quit != nil {
+	select {
+	case <-t.quit:
+		// do nothing, already closed
+
+	default:
 		close(t.quit)
-		t.quit = nil
 	}
 	
 	t.termioFini()
Fix data race in tScreen shutdown

Setting t.quit to nil while the mainLoop is running causes a
race condition when the Fini() method is called. This change
instead uses a select expression to avoid the nil check and set.