This code inspection warns you about fields being used both with and without locking, thus helping you detect potential problems with thread safety. Here is an example:
publicclassLockingSample{privatereadonlyList<object> _resources =newList<object>();privatereadonlyobject _lockObject =newobject();publicvoidAddResource(object resource){lock(_lockObject)
_resources.Add(resource);}publicvoidRemoveResource(object resource){// Warning: The field is sometimes used inside synchronized block// and sometimes used without synchronizationif(_resources.Contains(resource)){
_resources.Remove(resource);}}}
The inspection is not triggered on const fields and in private methods that have no synchronization inside but are always used from synchronized contexts.
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions. Learn more.
With your consent, JetBrains may also use cookies and your IP address to collect individual statistics and provide you with personalized offers and ads subject to the Privacy Notice and the Terms of Use. JetBrains may use third-party services for this purpose. You can adjust or withdraw your consent at any time by visiting the Opt-Out page.