From: psycho on 30 Mar 2010 06:11 On Mar 28, 6:18 am, Curious <fir5tsi...(a)yahoo.com> wrote: > > Depends what you're doing but then, in a word again, no. Well I guess > > that's harsh to say they are not useful. But I have never had to resort to > > using them in any high performance multi-threaded application I've ever > > made. However I have had to use lock correctly and carefully controlled my > > threads. > > > I'd bet you 25c you're not going to need them for your application. > > > Out of interest are you coming across some kind of issue with locking or > > performance which has caused you to question 'lock'? Or was it just an > > academic question? > > > For some reason 'lock' has come up a lot recently! I thought I'd cover it:http://www.gotinker.com/2010/03/11/locking-and-multi-threading/ > > > -- > > Mike > > GoTinker, C# Bloghttp://www.gotinker.com-Hide quoted text - > > Thanks for the answer! I never came across any issue with "lock". I > was grilled in a technical interview about "lock". I told him that I > used lock to resolve the issue with memory corruption. He then asked > me if there was a better method to use than to use lock, and that got > me. Lock keyword is just a convinient way to use Monitor Which means lock(obj) { // do something here } is equivalent to Monitor.Enter(obj); // do something Monitor.Exit(obj);
From: MarkusSchaber on 31 Mar 2010 05:33 On 30 Mrz., 12:11, psycho <paramvir.d...(a)gmail.com> wrote: > Lock keyword is just a convinient way to use Monitor > Which means > lock(obj) > { > // do something here > > } > > is equivalent to > > Monitor.Enter(obj); > // do something > Monitor.Exit(obj); Not exactly - more like Monitor.Enter(obj); try { // do something } finally { Monitor.Exit(obj); } But there are some special precautions, AFAIK, to handle async exceptions which can appear between Monitor.Enter and try.
From: MarkusSchaber on 31 Mar 2010 05:36 On 31 Mrz., 11:33, MarkusSchaber <m...(a)soloplan.de> wrote: > But there are some special precautions, AFAIK, to handle async > exceptions which can appear between Monitor.Enter and try. YFYI: You can find more infos at http://blogs.msdn.com/ericlippert/archive/2009/03/06/locks-and-exceptions-do-not-mix.aspx
First
|
Prev
|
Pages: 1 2 Prev: Find sub-list from a generic list Next: Out of Office settings 2007 outlook |