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

Re: Operator Overloading -- Inherently Thread Safe? by Ian

Ian
Mon Nov 22 08:18:04 CST 2004

"Cole Shelton" <scolemann@_NO_SPAM_yahoo.com> wrote:
>
> 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.


--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/



Re: Operator Overloading -- Inherently Thread Safe? by Jon

Jon
Mon Nov 22 08:17:08 CST 2004

Cole Shelton <scolemann@_NO_SPAM_yahoo.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too