jeme edited a comment on issue #417:
URL: https://github.com/apache/lucenenet/issues/417#issuecomment-779662497


   David Fowlers statement makes it sound like the implementation would call 
the delegate multiple times, I don't feel like that is quite an accurate way of 
describing the behavior. In the actual behavior, it makes a bit more sense why 
this happens.
   
   The basics is that the factory is called outside of a lock, which means if 
you call GetOrAdd simultaneously on two threads, each or their value factories 
will be executed.
   
   This may be a good read: 
https://andrewlock.net/making-getoradd-on-concurrentdictionary-thread-safe-using-lazy/
   
   ----
   Here are the usages I could find.
   
   Lucene.Net:
   
https://github.com/apache/lucenenet/blob/master/src/Lucene.Net/Support/IO/FileSupport.cs#L363
   
   
https://github.com/apache/lucenenet/blob/master/src/Lucene.Net/Support/Configuration/EnvironmentVariablesConfigurationProvider.cs#L67
   
   
https://github.com/apache/lucenenet/blob/master/src/Lucene.Net/Search/SearcherLifetimeManager.cs#L174
   
   Lucene.Net.TestFramework
   
https://github.com/apache/lucenenet/blob/f5cca0b1a7c855f2fe44a5cdd27763aab7acdf22/src/Lucene.Net.TestFramework/Support/Configuration/TestConfigurationFactory.cs#L56
   
   Lucene.Net.Spatial
   
https://github.com/apache/lucenenet/blob/d5c5ca4b066ae7ba4839519ec162594844fbc10a/src/Lucene.Net.Spatial/Prefix/PrefixTreeStrategy.cs#L225
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to