Page 1 of 1

Bug fix in SequenceGenerator

Posted: Thu Jun 08, 2017 10:47 am
by murtz
I have fixed a bug in SequenceGenerator class. Please see below.

Code: Select all

        public uint NextSequenceNumber()
        {
            lock (_syncSequenceNumber)
            {
                //Changed 0x7FFFFFFF to int.MaxValue for easy representation only
                if (_counter == int.MaxValue)
                    _counter = 0;

                //Return from within the lock body as value may get change by another thread before the call of return statement
                //_counter++;
                return ++_counter;
            }
            //No longer needed
            //return _counter;
        }

        public byte NextReferenceNumber()
        {
            lock (_syncReferenceNumber)
            {
                if (_byteCounter == byte.MaxValue)
                    _byteCounter = 0;

                //Return from within the lock body as value may get change by another thread before the call of return statement
                //_byteCounter++;
                return ++_byteCounter;
            }
            //No longer needed
            //return _byteCounter;
        }

Re: Bug fix in SequenceGenerator

Posted: Mon Jul 03, 2017 7:42 pm
by alt
Thank you for pointing this bug to me.