Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fix

import "sync"

// FixRaceCondition adds proper synchronization to prevent data races.
// This fix uses sync.RWMutex to protect concurrent access to shared state.
type SafeState struct {
mu sync.RWMutex
value interface{}
}

func (s *SafeState) Get() interface{} {
s.mu.RLock()
defer s.mu.RUnlock()
return s.value
}

func (s *SafeState) Set(v interface{}) {
s.mu.Lock()
defer s.mu.Unlock()
s.value = v
}