Is the static method thread safe

If I have a static method to convert one object to another object, is this method safe in C #?

public static AnotherDataClass Convert(MyDataClass target) { AnotherDataClass val = new AnotherDataClass(); // read infomration from target // put information into val; return val; } 

I just want to make the question clearer ....

when calling the conversion method .... we can assume that the target will not change. since the Convert method was only interested in the "attrubite" target

+4
source share
1 answer

No, it is not.

"The method would be thread safe if it accessed data that would not be accessible to any other thread." If this definition is correct, then the method is not thread safe.

Cause

MyDataClass seems to me to be a reference type, so there is a possibility that multiple threads might modify the target variable

+2
source

Source: https://habr.com/ru/post/1384502/


All Articles