{"action":"created","issue":{"url":"https://api.github.com/repos/bilal-fazlani/tracker-enabled-dbcontext/issues/13","labels_url":"https://api.github.com/repos/bilal-fazlani/tracker-enabled-dbcontext/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/bilal-fazlani/tracker-enabled-dbcontext/issues/13/comments","events_url":"https://api.github.com/repos/bilal-fazlani/tracker-enabled-dbcontext/issues/13/events","html_url":"https://github.com/bilal-fazlani/tracker-enabled-dbcontext/issues/13","id":61874224,"number":13,"title":"Can't the lock be removed ?","user":{"login":"bilal-fazlani","id":3396271,"avatar_url":"https://avatars.githubusercontent.com/u/3396271?v=3","gravatar_id":"","url":"https://api.github.com/users/bilal-fazlani","html_url":"https://github.com/bilal-fazlani","followers_url":"https://api.github.com/users/bilal-fazlani/followers","following_url":"https://api.github.com/users/bilal-fazlani/following{/other_user}","gists_url":"https://api.github.com/users/bilal-fazlani/gists{/gist_id}","starred_url":"https://api.github.com/users/bilal-fazlani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bilal-fazlani/subscriptions","organizations_url":"https://api.github.com/users/bilal-fazlani/orgs","repos_url":"https://api.github.com/users/bilal-fazlani/repos","events_url":"https://api.github.com/users/bilal-fazlani/events{/privacy}","received_events_url":"https://api.github.com/users/bilal-fazlani/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bilal-fazlani/tracker-enabled-dbcontext/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":{"login":"GeertvanHorrik","id":1246444,"avatar_url":"https://avatars.githubusercontent.com/u/1246444?v=3","gravatar_id":"","url":"https://api.github.com/users/GeertvanHorrik","html_url":"https://github.com/GeertvanHorrik","followers_url":"https://api.github.com/users/GeertvanHorrik/followers","following_url":"https://api.github.com/users/GeertvanHorrik/following{/other_user}","gists_url":"https://api.github.com/users/GeertvanHorrik/gists{/gist_id}","starred_url":"https://api.github.com/users/GeertvanHorrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GeertvanHorrik/subscriptions","organizations_url":"https://api.github.com/users/GeertvanHorrik/orgs","repos_url":"https://api.github.com/users/GeertvanHorrik/repos","events_url":"https://api.github.com/users/GeertvanHorrik/events{/privacy}","received_events_url":"https://api.github.com/users/GeertvanHorrik/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2015-03-15T17:47:19Z","updated_at":"2015-03-17T12:23:04Z","closed_at":"2015-03-15T20:12:22Z","body":"```\r\nprivate static TValue GetFromCache<TKey, TValue>(ConcurrentDictionary<TKey, TValue> dictionary, TKey key,\r\n            Func<TValue> func)\r\n        {\r\n            lock (dictionary)\r\n            {\r\n                if (!dictionary.ContainsKey(key))\r\n                {\r\n                    dictionary[key] = func();\r\n                }\r\n\r\n                return dictionary[key];\r\n            }\r\n        }\r\n```\r\n\r\nThe dictionary is `ConcurrentDictionary`. Can't the lock be removed ? What could be side-effect of removing lock on a `ConcurrentDictionary` ? I thought they are thread-safe."},"comment":{"url":"https://api.github.com/repos/bilal-fazlani/tracker-enabled-dbcontext/issues/comments/82317970","html_url":"https://github.com/bilal-fazlani/tracker-enabled-dbcontext/issues/13#issuecomment-82317970","issue_url":"https://api.github.com/repos/bilal-fazlani/tracker-enabled-dbcontext/issues/13","id":82317970,"user":{"login":"bilal-fazlani","id":3396271,"avatar_url":"https://avatars.githubusercontent.com/u/3396271?v=3","gravatar_id":"","url":"https://api.github.com/users/bilal-fazlani","html_url":"https://github.com/bilal-fazlani","followers_url":"https://api.github.com/users/bilal-fazlani/followers","following_url":"https://api.github.com/users/bilal-fazlani/following{/other_user}","gists_url":"https://api.github.com/users/bilal-fazlani/gists{/gist_id}","starred_url":"https://api.github.com/users/bilal-fazlani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bilal-fazlani/subscriptions","organizations_url":"https://api.github.com/users/bilal-fazlani/orgs","repos_url":"https://api.github.com/users/bilal-fazlani/repos","events_url":"https://api.github.com/users/bilal-fazlani/events{/privacy}","received_events_url":"https://api.github.com/users/bilal-fazlani/received_events","type":"User","site_admin":false},"created_at":"2015-03-17T12:23:04Z","updated_at":"2015-03-17T12:23:04Z","body":"@GeertvanHorrik \r\nStrange indeed, When tried in a console POC application, the behavior of lambda was as expected. \r\n\r\nAnyways, About removing of the locks, I did some research, I found that ConcurrentCollection does expose threadsafe methods, which will allow us to remove the locks. The one we can use is [GetOrAdd](https://msdn.microsoft.com/en-us/library/ee378677(v=vs.110).aspx). I am guessing this method locks the dictionary internally. "}}