NightOwl888 commented on issue #1063:
URL: https://github.com/apache/lucenenet/issues/1063#issuecomment-2526316653

   However, if we don't want to introduce these new allocations, we can create 
properties to wrap the `Interlocked` and `BitConversion` calls, which would put 
them neatly in one place in the class they are declared in.
   
   ```c#
   public class IndexWriter
   {
       // LUCENENET: Converted changeCount field to a property to make it 
interlocked (and volatile)
       private long threadUnsafeChangeCount; // increments every time a change 
is completed
       private long changeCount
       {
           get => Interlocked.Read(ref this.threadUnsafeChangeCount);
           set => Interlocked.Exchange(ref this.threadUnsafeChangeCount, value);
       }
   }
   ```
   
   Then the rest of the code wouldn't need to change to read or write to the 
"field" (which is now a property).
   


-- 
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: dev-unsubscr...@lucenenet.apache.org

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

Reply via email to