Can I lock MyClass from ThreadRunner.RunThread when sending it as an argument?
MyClass{
private static object locker = new object();
public void RunThreads{
for(int i=0;i<8;i++){
ThreadRunner.RunThread(locker);
}
}
}
Is this kosher, or should I have the logic of RunThread in MyClass so I don’t have to pass the locker object?
Edit: I corrected the
conststop the downvotes please!Since
lockeris static, it’s better to just declare it as:since lock objects should be constant anyway, and use it inside the thread code as:
that way you don’t need to pass it.