I can't come up with a way to make the Test() function goroutine safe. Even adding a Mutex exclusively for Test() won't work because it could still race with a goroutine calling other Getter/Setter functions. Instead I've added a warning to the documentation for the Test function which addresses #13
I've changed the mutex to an RWMutex since the map is safe for concurrent read, just not concurrent read/write. Assuming that most envy usage will be very read biased this should be worthwhile.
I've made sure there is a mutex around every function which mutates or reads the env (Except for the Temp() function)
Lastly, and this is likely to be the problematic part, I've altered Map to return a copy since it doesn't make sense (at least to me) to wrap it up with a Mutex inside envy but then just hand it over to external code which can read/write from/to it however it pleases.
This would possibly break existing code!
I can't come up with a way to make the
Test()
function goroutine safe. Even adding a Mutex exclusively forTest()
won't work because it could still race with a goroutine calling other Getter/Setter functions. Instead I've added a warning to the documentation for the Test function which addresses #13I've changed the mutex to an RWMutex since the map is safe for concurrent read, just not concurrent read/write. Assuming that most envy usage will be very read biased this should be worthwhile.
I've made sure there is a mutex around every function which mutates or reads the env (Except for the
Temp()
function)Lastly, and this is likely to be the problematic part, I've altered Map to return a copy since it doesn't make sense (at least to me) to wrap it up with a Mutex inside envy but then just hand it over to external code which can read/write from/to it however it pleases.