为list< T>。载有()是线程调用

编程入门 行业动态 更新时间:2024-10-28 04:17:13
本文介绍了为list< T>。载有()是线程调用 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的理解是,如果你正在使用C#泛型列表(列表),它可以支持多个并发读取器,但只有一个作家。而当你引入一个作家到混合,你还必须提供同步结构,以使操作线程安全的。

My understanding is that if you are using a generic list (List) in C#, that it can support multiple concurrent readers but only one writer. And when you introduce a writer into the mix, you must also provide synchronization constructs to make the operations thread safe.

时List.Contains认为读操作?换句话说,如果我调用这个方法,我需要担心一个作家可以在同一时间被写入这个名单?

Is List.Contains considered a read operation? In other words, if I am calling this method, do I need to worry that a writer may be writing to this List at the same time?

推荐答案

是的,你应该。基本上我都会同步进行的任何的,如果可以用于在同一时间写列表操作。

Yes, you should. Basically I would synchronize for any operation if the list might be used for writing at the same time.

一般来说,我觉得收藏品分为两类 - 这是创建,初始化,然后就再也没有再次改变(线程安全的)的人,和突变随着时间的人(不是线程安全的,所有访问锁)

Generally I find collections fall into two categories - ones which are created, initialized and then never changed again (thread-safe), and ones which are mutated over time (not thread-safe, lock for all access).

更多推荐

为list< T>。载有()是线程调用

本文发布于:2023-11-07 04:34:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   amp   list   GT   LT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!