在C#中的数组线程安全 [英] Thread safety in C# arrays

查看:204
本文介绍了在C#中的数组线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有2个不同的主题:

Does having 2 different threads :


  • 从一个C#数组一个读数(例如从第一位置),

  • ,另一个写入到相同的C#数组,但以不同的位置(例如到最后位置)

是线程安全与否?

(我的意思是这里没有锁定读也不是写操作)

is thread safe or not?
(And I mean here without locking reading nor writing)

推荐答案

此特定情况下是安全的,是的。

This particular case is safe, yes.

读取和写入到阵列的不同部分不与其它操作干扰

Reading and writing to different parts of an array does not interfere with the other operations.

然而,读取和写入到相同的位置可以给你的问题​​,这取决于元件的类型和元素的大小

However, reading and writing to the same location can give you problems, depending on the type of element, and the size of the elements.

这篇关于在C#中的数组线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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