I'm creating an object like this:
if (_cleaner == null)
{
_creation.WaitOne();
try
{
if (_cleaner == null)
{
//create object
}
}
finally
{
_creation.ReleaseMutex();
}
}
The reason i do the double check is because two threads can come simultaneously to the object creation and then I need obviously only one to create an object. Is there a better way to do it? So i dont have to check object existence twice?