You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @StephenCleary, thank you, I'm really enjoying reading and learning from this code and applying it to my own projects. I have a question which could possibly lead to a small improvement in the BoundActionField ... I'm not sure ... here goes.
You have the following property getter ... I understand perfectly ... it's simply checking what's stored in _field.
public bool IsEmpty => Interlocked.CompareExchange(ref _field, null, null) == null;
But later in the TryUpdateContext method you have the following line of code:
var original = Interlocked.CompareExchange(ref _field, _field, _field);
As far as I can interpret, its purpose is exactly the same as in the property getter ... to grab the value of _field. But here you've used _field, _field for the next two parameters instead of null, null. I don't understand why. It seems "bad" to me, in comparison to supplying nulls. Is there a deliberate reason to this choice, or just randomness?
Thank you.
The text was updated successfully, but these errors were encountered:
Is there anything you would change about your code after reading this? In particular, I noted that this class uses Volatile.Read where you would use Interlocked.CompareExchange(ref _value, null, null) ... is there a difference / comparative advantage?
Yes, it should be using null, null instead of _field, _field. Thanks!
Regarding Volatile vs CompareExchange, they're pretty much equivalent. The CompareExchange technically doesn't have to do a full memory fence like Volatile.Read does, but I believe it does anyway for historical reasons.
Hi @StephenCleary, thank you, I'm really enjoying reading and learning from this code and applying it to my own projects. I have a question which could possibly lead to a small improvement in the
BoundActionField
... I'm not sure ... here goes.You have the following property getter ... I understand perfectly ... it's simply checking what's stored in
_field
.public bool IsEmpty => Interlocked.CompareExchange(ref _field, null, null) == null;
But later in the
TryUpdateContext
method you have the following line of code:var original = Interlocked.CompareExchange(ref _field, _field, _field);
As far as I can interpret, its purpose is exactly the same as in the property getter ... to grab the value of
_field
. But here you've used_field, _field
for the next two parameters instead ofnull, null
. I don't understand why. It seems "bad" to me, in comparison to supplying nulls. Is there a deliberate reason to this choice, or just randomness?Thank you.
The text was updated successfully, but these errors were encountered: