From e8149f0ab1c596724de0b8de325ec06565ed7d93 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Tue, 28 Apr 2020 00:25:12 +0300 Subject: [PATCH] synchronize access to Console (fixes #48) --- colorable_windows.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/colorable_windows.go b/colorable_windows.go index b9e9363..e85b0cb 100644 --- a/colorable_windows.go +++ b/colorable_windows.go @@ -10,6 +10,7 @@ import ( "os" "strconv" "strings" + "sync" "syscall" "unsafe" @@ -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)))