none
IsDisposed public getter is not thread safe in CompositeDisposable and RefCountDisposable

    Question

  • Hi,

    I’ve noticed that IsDisposed public getter is not thread safe in CompositeDisposable and RefCountDisposable while in all the other disposables it’s protected either by using a lock or a volatile member variable.

    I would expect that all the disposables provide a strong guarantee for the public IsDisposed flag and it should reflect the correct disposable state regardless of the thread that checks it.

    Could you please comment on that? Is it a bug in those two observables or you didn’t protect the public getter there for a reason?

    CompositeDisposable (no protection):

        private bool _disposed;
    
        public bool IsDisposed
        {
          get
          {
            return this._disposed;
          }
        }

    SerialDisposable (lock protection):

        public bool IsDisposed
        {
          get
          {
            lock (this._gate)
              return this._disposed;
          }
        }

    BooleanDisposable (volatile var protection)

        private volatile bool _isDisposed;
    
        public bool IsDisposed
        {
          get
          {
            return this._isDisposed;
          }
        }
    


    Thx, Sebastian 

    Saturday, June 28, 2014 10:40 AM

All replies