防守防多线程类实现多线程

2023-09-05 23:24:15 作者:我是逗比我比你逗

我有一个对象,它是不安全的多线程应用程序(在几个方面),我想提供内部检查,以确保关键的方法,不能同时访问。

I have an object that is not safe for multithreaded applications (in several ways), and I want to provide an internal check to make sure that critical methods are not accessed concurrently.

问题

我应该采用什么技术来检测和访问我的课prevent多线程?

What techniques should I employ to detect and prevent multiple threads from accessing my class?

是否足以跟踪Thread.ID上的所有方法,属性等,消费者可以使用?

Is it sufficient to track the Thread.ID on all methods, properties, etc. that the consumer may use?

推荐答案

只是记录,它不是线程安全的。这是在.NET中使用的类的约定。

Just document that it isn't thread safe. That's the convention used by the classes in .NET.

 
精彩推荐
图片推荐