Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singleton code example is not thread safe #14

Open
isurukdniss opened this issue Jul 24, 2018 · 0 comments
Open

Singleton code example is not thread safe #14

isurukdniss opened this issue Jul 24, 2018 · 0 comments

Comments

@isurukdniss
Copy link

The provided example for Singleton design pattern is not thread safe. This is the most basic implementation of the Singleton pattern. Please add the thread safe, lazy implementation.

public sealed class Singleton
{
    private static readonly Lazy<Singleton> lazy =
        new Lazy<Singleton>(() => new Singleton());
    
    public static Singleton Instance { get { return lazy.Value; } }

    private Singleton()
    {
    }
}

Below article from Jon Skeet would be helpful
http://csharpindepth.com/Articles/General/Singleton.aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant