public void BeforeClass() { mySliceInt = BitSlice.Int(4); mySliceEnum = BitSlice.Enum <E4>(mySliceInt); mySliceBool = BitSlice.Bool(mySliceEnum); mySliceE1 = BitSlice.Enum <E1>(mySliceBool); }
public void InterlockedUpdateStressTest2() { const int bitCount = 8; const int n = (1 << bitCount) - 1; var slice1 = BitSlice.Int(bitCount); var slice2 = BitSlice.Int(bitCount, slice1); var slice3 = BitSlice.Int(bitCount, slice2); var slice4 = BitSlice.Int(bitCount, slice3); for (var i = 0; i < 1000; i++) { var state = 0; Parallel.Invoke(() => { for (var j = 0; j < n; j++) { slice1.InterlockedUpdate(ref state, slice1[state] + 1); } }, () => { for (var j = 0; j < n; j++) { slice2.InterlockedUpdate(ref state, slice2[state] + 1); } }, () => { for (var j = 0; j < n; j++) { slice3.InterlockedUpdate(ref state, slice3[state] + 1); } }, () => { for (var j = 0; j < n; j++) { slice4.InterlockedUpdate(ref state, slice4[state] + 1); } }); Assert.AreEqual(n, slice1[state]); Assert.AreEqual(n, slice2[state]); Assert.AreEqual(n, slice3[state]); Assert.AreEqual(n, slice4[state]); } }