Functions such as Get(), GetSlice(), Delete() that uses the appData data-structure are currently not thread-safe. These functions call exists() to identify if a named object already exists. It then uses the index returned by exists() to manipulate that named object. But we grab the lock protecting the map only within exists(). Once exists() returns, we cannot be sure that the returned index still points to the object we want as some other goroutine could have modified the map in the mean time. Therefore the lock protecting the map should be acquired before calling exists() and released only after the operation on that object is completed.
Functions such as
Get()
,GetSlice()
,Delete()
that uses theappData
data-structure are currently not thread-safe. These functions callexists()
to identify if a named object already exists. It then uses the index returned byexists()
to manipulate that named object. But we grab the lock protecting the map only withinexists()
. Onceexists()
returns, we cannot be sure that the returned index still points to the object we want as some other goroutine could have modified the map in the mean time. Therefore the lock protecting the map should be acquired before callingexists()
and released only after the operation on that object is completed.