Operator Overloading -- Inherently Thread Safe?

  • Thread starter Thread starter Cole Shelton
  • Start date Start date
C

Cole Shelton

Hi all,

If an overloaded operator method contains multiple lines of code does it
need to be synchronized at the class level or is it inherently thread safe?

TIA
Cole
 
Cole Shelton said:
If an overloaded operator method contains multiple lines of code does it
need to be synchronized at the class level or is it inherently thread safe?

There's nothing inherently thread-safe about operators, any more than
there is with any other method. That doesn't mean it needs to be
synchronized at the class level though - as ever, it depends on the
usage and any number of other things. How thread-safe you make your
classes is up to you.
 
Cole Shelton said:
If an overloaded operator method contains multiple lines of code does it
need to be synchronized at the class level or is it inherently thread
safe?

It is not inherently thread safe. It may or may not need to be
synchronized - it will depend on what you're doing with it.

The fact that something is an overloaded operator is of no significance to
threading. The answer to your question is exactly the same as it would be
for any method. As far as the CLR is concerned, overloaded operators are
just methods like any other.
 
Back
Top