Skip to content

Commit

Permalink
synchronize access to Console (fixes mattn#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
segrey committed Apr 27, 2020
1 parent 4e32bdb commit e8149f0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions colorable_windows.go
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"syscall"
"unsafe"

Expand Down Expand Up @@ -430,8 +431,14 @@ func atoiWithDefault(s string, def int) (int, error) {
return strconv.Atoi(s)
}

var (
writeMutex sync.Mutex
)

// Write writes data on console
func (w *Writer) Write(data []byte) (n int, err error) {
writeMutex.Lock()
defer writeMutex.Unlock()
var csbi consoleScreenBufferInfo
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))

Expand Down

0 comments on commit e8149f0

Please sign in to comment.