是C#基本数组动荡? [英] are c# primitive arrays volatile?
问题描述
我声明数组一样,私人双[]数组=新的双[长度]
。它是安全的在一个线程中更新此数组项,并在另一个线程读取?我是否有最新的价值?
I declare array like that private double[] array = new double[length]
. Is it safe to update this array items in one thread and read in another thread? Will I have up to date value?
请注意,我不一一列举数组。我只按索引访问它的项目。
Note i do not enumerate array. I only access its items by index.
推荐答案
挥发性不保证值的新鲜感。它可以防止一些优化,但不保证线程同步。
Volatile does not guarantee freshness of a value. It prevents some optimizations, but does not guarantee thread synchronization.
双击不guaranted是的更新原子。因此,更新/阅读双打的阵列,而不同步将不会在所有的智慧或不挥发,你可以阅读部分写入的值是线程安全的。
Double is not guaranted to be updated atomically. So updating/reading arrays of doubles without synchronization will not be thread safe at all wit or without volatile as you may read partially written values.
这篇关于是C#基本数组动荡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!