Created
July 31, 2014 04:30
-
-
Save droyad/37e047b07214de138da1 to your computer and use it in GitHub Desktop.
Lazy Threadsafe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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