防守防多线程类实现 [英] Defensive anti-multithreading class implementation

查看:106
本文介绍了防守防多线程类实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象,它是<一个href="http://blogs.msdn.com/b/ericlippert/archive/2009/10/19/what-is-this-thing-you-call-thread-safe.aspx"相对=nofollow>不安全的多线程应用程序(在几个方面),我想提供内部检查,以确保关键的方法,不能同时访问。

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.

这篇关于防守防多线程类实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆