jpountz commented on code in PR #13606:
URL: https://github.com/apache/lucene/pull/13606#discussion_r1756914836


##########
lucene/core/src/java/org/apache/lucene/search/HitsThresholdChecker.java:
##########
@@ -24,6 +24,10 @@ abstract class HitsThresholdChecker {
   /** Implementation of HitsThresholdChecker which allows global hit counting 
*/
   private static class GlobalHitsThresholdChecker extends HitsThresholdChecker 
{
     private final LongAdder globalHitCount = new LongAdder();
+    // Cache whether the threshold has been reached already. It is not 
volatile or synchronized on
+    // purpose to contain the overhead of reading the value similarly to what 
String#hashCode()
+    // does. This does not affect correctness.
+    private boolean thresholdReached = false;

Review Comment:
   Indeed it may be accessed by multiple threads, but it is still safe, we may 
just have multiple threads independently set it to the same value. If the 
threshold isn't reached, then the value may only be `false`. Vice-versa if we 
read a `true`, the the threshold is guaranteed to have been reached. It is 
possible to read a `false` while the threshold has been reached (e.g. if a 
write in another thread hasn't been made visible to the current thread), but 
then this thread will take care of setting the boolean to true, same value that 
has been set by the other thread. This SO post tries to answer the same 
question for String#hashCode: 
https://stackoverflow.com/questions/41704185/is-javas-string-hashcode-function-thread-safe-if-its-cache-setter-does-not-us



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to