且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

迭代通用并发集合

更新时间:2023-09-19 17:37:46

当然可以。从这些类的文档来看,即使从他们的名字中也不是那么明显吗?这就是他们的设计目标。此外,这样的集合可以作为线程的某种线程同步实用程序服务器,因为,例如,它们序列化由不同线程添加到同一集合的数据。



-SA

Is safe to iterate over a generic concurrent collections on worker threads without locking on them (ConcurrentQueue, ConcurrentDictionary, ConcurrentStack, etc)?

Yes of course. Isn't that apparent from the documentation of these classes, even from their names? This is what they have been designed for. Moreover, such collections can server as a certain kind of thread synchronization utility for threads, because, say, they serialize data added to the same collection by different threads.

—SA