1

My question is 99% answered in the post referenced below, but I'd like to know how the method is to be called. Since I cannot comment on the solution provided (too low reputation), I was advised to post my comment as a new question.

Original post and answer (by Eugene): Why is there no overload of Interlocked.Add that accepts Doubles as parameters?

Question: trying to program Parallel::For loop which requires an Interlocked::Add on doubles, so the example is great. But how do I call this function?

Say B is to be added to A, both are doubles.

Would the call be A = Add(A, B); ? If not, what should it be?

Community
  • 1
  • 1
jdelange
  • 763
  • 2
  • 10
  • 22

1 Answers1

-1

It'd suggest using the "classic" form of lock-free operation:

  • Copy the shared variable to a local variable
  • Calculate the operation result
  • InterlockedCompareExchange the result, local variable and shared variable. If it fails (meaning the shared variable has changed in the meantime), retry the whole operation.
Medinoc
  • 6,577
  • 20
  • 42
  • There is a C# example here that does that: [Link](http://msdn.microsoft.com/en-us/library/cd0811yf%28v=vs.110%29.aspx) which I translated to Cli (doesn't work yet). But it would be nice to know how to call and implement the method provided by Eugene. – jdelange May 28 '14 at 10:05