-
-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Did some view onto, hope you find some useful.
ImTools/src/ImTools/ImTools.cs
Line 534 in 56b7f53
| throw new InvalidOperationException(_errorRetryCountExceeded); |
Also it is public, it may deliver some caveats to possible users:
- Spin probably should yield for better CPU https://referencesource.microsoft.com/#mscorlib/system/threading/thread.cs,dd960cd58d3d20c1,references
- Default counter should in public API, not private hidden surprise in production.
- Consider return error(value tuple, option, or by ref return) result from Swap instead of throwing exception. Retry exceed could be normal condition on low level.
- Reproduce in test retry count reached via one fast and one slow getNewValue. Until getNewValue is hanged and if Thread.Yield used I guess retry could be made infinite by default.
[TestFixture] - Consider make it more private-internal if possible.
- T is class. Consider adding know primiteves swap like Interlocked for long int etc.
ImTools/src/ImTools/ImTools.cs
Line 524 in 56b7f53
public static T Swap<T>(ref T value, Func<T, T> getNewValue) where T : class - consider document
ImTools/src/ImTools/ImTools.cs
Line 489 in 56b7f53
/// <summary>Compares current Referred value with <paramref name="currentValue"/> and if equal replaces current with <paramref name="newValue"/></summary> reference equalsinstead ofequals(to be crystal clear). - CompareAndSwap or other like name may be better name
ImTools/src/ImTools/ImTools.cs
Line 497 in 56b7f53
public bool TrySwapIfStillCurrent(T currentValue, T newValue) => - does compares by reference, but returns by bool depending on possible
ImTools/src/ImTools/ImTools.cs
Line 498 in 56b7f53
Interlocked.CompareExchange(ref _value, newValue, currentValue) == currentValue; ==https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/equality-comparison-operator. Same seems hereImTools/src/ImTools/ImTools.cs
Line 531 in 56b7f53
if (Interlocked.CompareExchange(ref value, newValue, oldValue) == oldValue) - Consider document usage scenarios, i.e. it seems not for long running operations, not ordered operations (while does not orders getNewValue delegates).
- Inspire https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-579.pdf :) and think of laptop Intel with 12 cores or Ryzen with 32 cores https://en.wikipedia.org/wiki/Ryzen (these are commodities now)