难道一个线程开始有内隐记忆障碍? [英] Does a thread start have implicit memory barrier?

查看:110
本文介绍了难道一个线程开始有内隐记忆障碍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即。当我开始一个新的线程,它是安全的读取新启动的线程的线程开始前初始化的变量?

i.e. when I start a new thread, is it safe to read any variables initialized before the thread start from the newly started thread?

UPD我为什么要问?因为有些开发商认为它确实有,并且不使用任何外显记忆障碍存在。我无法重现任何错误在code。然而,文档 http://msdn.microsoft.com /en-us/library/ms686355(v=vs.85).aspx 并没有说这是安全的。

UPD why I'm asking? Because some developers assume that it does have, and don't use any explicit memory barriers there. And I couldn't reproduce any bugs in that code. However, documentation http://msdn.microsoft.com/en-us/library/ms686355(v=vs.85).aspx doesn't say this is safe.

推荐答案

是的,操作系统提供了隐性障碍。它不能获得线程开始没有采取一个内部锁保护线程调度的数据结构。

Yes, the operating system provides the implicit barrier. It can't get the thread started without taking an internal lock that protects the thread scheduler data structures.

这是没有明确的答应的,我知道。由于.NET 2.0,也不再是一个线程和ProcessThread之间存在直接的对应关系。这种联系在了想要实现与光纤一个线程SQL Server团队的要求打破。这并没有实际发生,他们放弃了,当他们不能使它足够可靠的项目。鉴于这一项目,并没有主流的项目中,我知道的结果曾经试图利用这一点再次,以及执行线程支持的难度不使用锁,我会说这是安全的假设你可以依靠的隐性障碍。

Which isn't explicitly promised that I know of. Since .NET 2.0, there is no longer a direct correspondence between a Thread and a ProcessThread. This link was broken at the request of the SQL Server team that wanted to implement a Thread with a fiber. This did not actually happen, they gave up on the project when they couldn't make it reliable enough. Given the outcome of this project and no mainstream project I know of that has ever tried to take advantage of this again, as well as the difficulty of implementing Thread support that doesn't use a lock, I'd say it is safe to assume you can rely on the implicit barrier.

这篇关于难道一个线程开始有内隐记忆障碍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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