No, it's not thread-safe. Imagine it's called twice at the same time with the same ID, which isn't previously present.
Both threads would get as far as RetrieveUser
, and they'd both call _users.Add(id, u)
. The second call would fail because the key would already exist in the dictionary.
(As an aside, I'd strongly recommend using braces for locks, if statements etc, for the sake of readability.)