Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using SyncLock
Message
From
24/01/2011 12:06:19
 
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01496120
Message ID:
01497206
Views:
47
>This looks like the 'super-safe' C# implementation:
public sealed class Singleton
>{
>   private static volatile Singleton instance;
>   private static object syncRoot = new Object();
>
>   private Singleton() {}
>
>   public static Singleton Instance
>   {
>      get 
>      {
>         if (instance == null) 
>         {
>            lock (syncRoot) 
>            {
>               if (instance == null) 
>                  instance = new Singleton();
>            }
>         }
>
>         return instance;
>      }
>   }
>}
(from http://msdn.microsoft.com/en-us/library/ff650316.aspx). Only problem is that VB doesn't have 'volatile' :-{


This "volatile" keyword is a new one for me (been around awhile, but I guess I hadn't heard of it). The link you provided to MSDN states that if your member is declared using the volatile keyword, then you don't have to use a lock ... so, if that's the case, then I'm confused why you did ... guess I should probably read up on it more at some point.

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform