Fixed rare index bug when using multiple multithreading consumers
This commit is contained in:
parent
faf6c99c19
commit
a838dacf2a
@ -295,6 +295,11 @@ public sealed class MultiThreadedRng<TNum> : IRandom<TNum>, IDisposable where TN
|
|||||||
// Made a local copy of the current pointer:
|
// Made a local copy of the current pointer:
|
||||||
var myPointer = this.currentBufferPointer;
|
var myPointer = this.currentBufferPointer;
|
||||||
|
|
||||||
|
// Issue #8: This might happens when the current thread was interrupted by another thread, and
|
||||||
|
// the other thread has already updated the pointer. In this case, we start over again.
|
||||||
|
if (myPointer >= BUFFER_SIZE)
|
||||||
|
goto Start;
|
||||||
|
|
||||||
// Increment the pointer for the next thread or call:
|
// Increment the pointer for the next thread or call:
|
||||||
var nextPointer = myPointer + 1;
|
var nextPointer = myPointer + 1;
|
||||||
|
|
||||||
@ -303,7 +308,7 @@ public sealed class MultiThreadedRng<TNum> : IRandom<TNum>, IDisposable where TN
|
|||||||
goto Start;
|
goto Start;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Case: Success. We updated the pointer and, thus, can use the read number.
|
// Case: Success. We updated the pointer and, thus, can use it to read the number.
|
||||||
//
|
//
|
||||||
return this.currentBuffer[myPointer];
|
return this.currentBuffer[myPointer];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user