简体   繁体   中英

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? The more complex the better really...

.NET 4.0 Thread-Safe Collections

Though targeting Windows rather than just .NET, Joe Duffy's book is worth noting: Concurrent Programming on Windows

MSDN has some good information on asynchronous programming in .NET. Check out Asynchronous Programming Design Patterns .

Also check out the Monitor and Mutex classes in System.Threading

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. These are just a few tools; I would suggest a simple Google of "atomic C#, F#.."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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