Skip to content

Instantly share code, notes, and snippets.

@droyad
Created July 31, 2014 04:30
Show Gist options
  • Select an option

  • Save droyad/37e047b07214de138da1 to your computer and use it in GitHub Desktop.

Select an option

Save droyad/37e047b07214de138da1 to your computer and use it in GitHub Desktop.
Lazy Threadsafe
Lazy<int> _lazy;
void Main()
{
_lazy = new Lazy<int>(CreateInt);
for(int x = 0; x < 10; x++)
{
new Thread(Run).Start();
}
}
void Run()
{
_lazy.Value.Dump();
}
int CreateInt()
{
"CreateInt".Dump();
for(int x = 0; x < 1000000000; x++) {}
return 1234;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment