Fixed rare race condition in name table when deserializing on device with ARM processors (#2602)
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
@@ -78,7 +79,12 @@ namespace Newtonsoft.Json
|
||||
hashCode -= hashCode >> 5;
|
||||
|
||||
// make sure index is evaluated before accessing _entries, otherwise potential race condition causing IndexOutOfRangeException
|
||||
var index = hashCode & _mask;
|
||||
#if NET20 || NET35 || NET40
|
||||
int mask = Thread.VolatileRead(ref _mask);
|
||||
#else
|
||||
int mask = Volatile.Read(ref _mask);
|
||||
#endif
|
||||
var index = hashCode & mask;
|
||||
var entries = _entries;
|
||||
|
||||
for (Entry entry = entries[index]; entry != null; entry = entry.Next)
|
||||
@@ -160,7 +166,12 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
}
|
||||
_entries = newEntries;
|
||||
_mask = newMask;
|
||||
|
||||
#if NET20 || NET35 || NET40
|
||||
Thread.VolatileWrite(ref _mask, newMask);
|
||||
#else
|
||||
Volatile.Write(ref _mask, newMask);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static bool TextEquals(string str1, char[] str2, int str2Start, int str2Length)
|
||||
|
||||
Reference in New Issue
Block a user