NightOwl888 opened a new pull request, #854:
URL: https://github.com/apache/lucenenet/pull/854

   Fixes #841. Part of #265.
   
   This adds an atomic `CompareAndSetIsOpen(bool expect, bool update)` method 
to `BaseDirectory` and `BaseDirectoryWrapper` that can be used to ensure only a 
single call to `Dispose(bool)` will succeed. This is the same method signature 
as `J2N.Threading.Atomic.AtomicBoolean` and can be used the same way (without 
the extra heap allocation).
   
   ```c#
   protected override void Dispose(bool disposing)
   {
       if (!CompareAndSetIsOpen(expect: true, update: false)) return;
   
       // Dispose unmanaged resources
       if (disposing)
       {
           // Dispose managed resources
       }
   }
   ```
   
   This fixes `NRTCachingDirectory` (as well as all other directories) so they 
don't throw exceptions when `Dispose()` is called multiple times.
   
   This of course means that `EnsureOpen()` will be active immediately when 
`Dispose()` is first called, so be mindful of its usage when the `Dispose()` 
method needs to call local methods to clean up.
   
   


-- 
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: [email protected]

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

Reply via email to