diff --git a/serial_windows.go b/serial_windows.go index 01fc9a6..e2c40f5 100644 --- a/serial_windows.go +++ b/serial_windows.go @@ -17,9 +17,13 @@ package serial */ -import ("syscall") +import ( + "syscall" + "sync" +) type windowsPort struct { + mu sync.Mutex handle syscall.Handle } @@ -58,8 +62,10 @@ func nativeGetPortsList() ([]string, error) { } func (port *windowsPort) Close() error { + port.mu.Lock() defer func() { port.handle = 0 + port.mu.Unlock() }() if port.handle == 0 { return nil