我寫了一段關於單例模式實現的代碼。不確定其正確性。請給點建議。謝謝。單例實現
public class Singleton
{
public Singleton Instance
{
get
{
if (_instance == null)
{
if (_mutexCreation.WaitOne(0))
{
try
{
if (_instance == null)
{
_instance = new Singleton();
}
}
finally
{
_mutexCreation.ReleaseMutex();
_eventCreation.Set();
}
}
else
{
_eventCreation.WaitOne();
}
}
return _instance;
}
}
private Singleton() { }
private static Singleton _instance;
private static Mutex _mutexCreation = new Mutex();
private static ManualResetEvent _eventCreation = new ManualResetEvent(false);
}
請用任何語言對此進行標記,以便從該社區接收專家。 :) – sarnold 2011-04-15 08:31:24
它看起來像C#... – shoosh 2011-04-15 08:35:42
我剛剛標記。 :) – lichaoir 2011-04-15 08:49:10