在C#是在32位处理器危险的Int64使用 [英] Under C# is Int64 use on a 32 bit processor dangerous

查看:160
本文介绍了在C#是在32位处理器危险的Int64使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该MS的文档,一个32位Intel的计算机上分配一个64位的值不是一个原子操作中读取;也就是说,该操作不是线程安全的。这意味着,如果两个人的值同时分配给一个静态的Int64 字段,字段的最终值是无法预测的。

I read in the MS documentation that assigning a 64-bit value on a 32-bit Intel computer is not an atomic operation; that is, the operation is not thread safe. This means that if two people simultaneously assign a value to a static Int64 field, the final value of the field cannot be predicted.

三部分的问题:


  • 这是真的

  • 这是不是我将现实世界中的烦恼?

  • 如果我的应用程序是多线程做我真的需要围绕与我所有的的Int64 任务锁码?

  • Is this really true?
  • Is this something I would worry about in the real world?
  • If my application is multi-threaded do I really need to surround all my Int64 assignments with locking code?

推荐答案

这是不是你遇到的每一个变量。如果某些变量用作共享状态或东西(包括但不限于的部分静态字段),你应该考虑这个问题的护理。它是完全非问题为在时间未悬挂作为在封闭或一个迭代变换被关闭在一个后果,由单一的功能被使用的局部变量(因此,一个单一的线程)。

This is not about every variable you encounter. If some variable is used as a shared state or something (including, but not limited to some static fields), you should take care of this issue. It's completely non-issue for local variables that are not hoisted as a consequence of being closed over in a closure or an iterator transformation and are used by a single function (and thus, a single thread) at a time.

这篇关于在C#是在32位处理器危险的Int64使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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