lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicholas Paldino <casper...@caspershouse.com>
Subject Re: RAMDirectory code - locking?
Date Tue, 19 Mar 2013 22:19:56 GMT
Brad et al,

You are correct, it is unsafe in that it exposes the synchronization object that is used (since
this is accessible by anything that has a reference to it).

At worst, you're exposing that object to deadlocks (or possible DoS depending on how exposed
the reference is).

General best practice says to store it as a private implementation detail (this is a leaky
implementation).

If there are synchronization issues involving that and other objects, it's usually indicative
of a larger design issue.

- Nick

On Mar 19, 2013, at 5:43 PM, "Allan, Brad (Wokingham)" <Brad.Allan@Fiserv.com> wrote:

> to confirm my question is related to how the locking is being done.
> Thanks.
> 
> (Sent from my Blackberry device)
> Brad Allan
> Development Lead
> Risk & Compliance
> Fiserv
> Office: +44 (0) 845 013 1137
> Mobile: +44 (0) 7866 720024
> Fax: +44 (0) 845 013 1010
> www.fiserv.com
> 
> ----- Original Message -----
> From: Rob Cecil [mailto:rob.cecil@gmail.com]
> Sent: Tuesday, March 19, 2013 05:16 PM
> To: user@lucenenet.apache.org <user@lucenenet.apache.org>
> Subject: Re: RAMDirectory code - locking?
> 
> I think the question is more about Lock(this) rather than
> Lock(mySimpleObject), e.g.:
> 
> http://stackoverflow.com/questions/2319286/what-to-pass-to-the-lock-keyword
> 
> 
> On Tue, Mar 19, 2013 at 4:38 PM, Anders Lybecker <anders@lybecker.com>wrote:
> 
>> Hi Brad,
>> 
>> I'm not really sure what your question is?
>> 
>> Is use of the C# Lock keyword safe in RamDirectory? Yes it is. Is it a
>> performance issue? No, not really. It is common in multi-threaded code
>> 
>> Regards,
>> Anders Lybecker
>> 
>> 
>> On Tue, Mar 19, 2013 at 6:22 PM, Allan, Brad (Wokingham) <
>> Brad.Allan@fiserv.com> wrote:
>> 
>>> There are a number of
>>> 
>>> 'lock (this)'
>>> 
>>> statements in the code?
>>> 
>>> 
>>> 
>>> Just wanting to check this has been considered and was considered safe.
>>> 
>>> 
>>> 
>>> I'm used to seeing the use of some sort of Locker object to do this.
>>> 
>>> 
>>> 
>>> Public class Bla {
>>> 
>>>         private static Object locker = new Object();
>>> 
>>> 
>>> 
>>>         Public void someMethod() {
>>> 
>>>                 Lock(locker) {
>>> 
>>>                          //do some stuff!
>>> 
>>>                 }
>>> 
>>>         }
>>> }
>>> 
>>> Brad Allan
>>> Development Lead
>>> Risk & Compliance
>>> Fiserv
>>> Office: +44 (0) 845 013 1137
>>> Mobile: +44 (0) 7866 720024
>>> www.fiserv.com<http://www.fiserv.com/>
>>> 
>>> 
>>> ________________________________
>>> 
>>> CheckFree Solutions Limited (trading as Fiserv)
>>> Registered Office: Eversheds House, 70 Great Bridgewater Street,
>>> Manchester, M15 ES
>>> Registered in England: No. 2694333
> 
> ________________________________
> 
> CheckFree Solutions Limited (trading as Fiserv)
> Registered Office: Eversheds House, 70 Great Bridgewater Street, Manchester, M15 ES
> Registered in England: No. 2694333
> 

Mime
View raw message