简体   繁体   English

.NET Framework中的线程安全类的示例?

[英]Examples of thread safe classes in the .NET Framework?

I'm currently working on code which is supposed to be thread safe. 我目前正在研究应该是线程安全的代码。 Lots of asynchronous calls and events and stuff that generally requires quite a bit of work to keep synchronized and thread safe. 许多异步调用和事件以及通常需要大量工作才能保持同步和线程安全的内容。

Are there any classes in the .NET framework which deal with this sort of thing, which I could look at (decompile), to see how things are supposed to be done? .NET框架中是否有任何类可以处理(反编译)这类事情,以了解应该如何完成这些工作? The more complex the better really... 越复杂越好...

.NET 4.0 Thread-Safe Collections .NET 4.0线程安全集合

Though targeting Windows rather than just .NET, Joe Duffy's book is worth noting: Concurrent Programming on Windows 尽管不仅仅针对.NET,而且针对Windows,但Joe Duffy的书值得注意: Windows上的并发编程

MSDN has some good information on asynchronous programming in .NET. MSDN具有有关.NET中异步编程的一些很好的信息。 Check out Asynchronous Programming Design Patterns . 查看异步编程设计模式

Also check out the Monitor and Mutex classes in System.Threading 还要检查System.Threading中的MonitorMutex类。

There are a few ways to keep things atomic. 有几种方法可以保持原子性。 There are classes that support fencing, such that code is guaranteed to execute in a certain order. 有些类支持隔离,因此可以确保代码按特定顺序执行。 You can use the keyword volatile to ensure that variable access is atomic (Read from memory each use) and that you have no phantom reads. 您可以使用关键字volatile来确保变量访问是原子的(每次使用都从内存中读取)并且没有幻像读取。 These are just a few tools; 这些只是一些工具。 I would suggest a simple Google of "atomic C#, F#.." 我建议使用一个简单的Google,“原子C#,F#..”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM