Fixed rare index bug when using multiple multithreading consumers

This commit is contained in:
Thorsten Sommer committed 2023-11-14 15:38:41 +01:00
1 parent faf6c99c19
commit a838dacf2a
1 file changed
+6 -1
+6 -1
View File
@@ -295,6 +295,11 @@ public sealed class MultiThreadedRng<TNum> : IRandom<TNum>, IDisposable where TN
// Made a local copy of the current pointer:
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:
var nextPointer = myPointer + 1;
@@ -303,7 +308,7 @@ public sealed class MultiThreadedRng<TNum> : IRandom<TNum>, IDisposable where TN
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];
}