After posting this question:http://stackoverflow.com/questions/781189/how-to-lock-on-an-integer-in-cMany of the answers made me feel that I'm a 'sinner' for using lock in my web apps. I never thought this is a problem (if used wisely), what about you? Do you ever use it in your web applications?I don't see how a web application can be written without locking, for example if you want to load some data from a database and you want to be sure that no other thread will load it (also for singletons), normally you use locking, for example:\[code\]private _locker = new object();private YourClass[] _data;public YourClass[] Data{ get { if(_data =http://stackoverflow.com/questions/781532/= null) { lock( _locker) { // get your data _data = GetYourData(); } } return _data; }}\[/code\]Is there a problem with this?!Edit
lease note that I'm referring to a single server scenario here, for a server farm you need some distributed locking mechanism, but you don't expect every site you create to get millions of hits in a couple of weeks, do you? What if you need locking, should you create your site with that distributed locking, isn't that too much for an application which you have no idea whether it will ever need to be scaled or not? Besides computers have gotten really fast these days, one server can handle tons of traffic and this has been proven so many times, some examples are plentyoffish.com and this very site you're using right now, do some googling and I'm sure you'll come across so many others.
