“自由线程"与“自由线程"之间的区别在于:和“线程安全" [英] Difference between "free-threaded" and "thread-safe"

查看:182
本文介绍了“自由线程"与“自由线程"之间的区别在于:和“线程安全"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我看到术语自由线程"来描述类或方法.它似乎与线程安全"具有相似或相同的含义.

Sometimes I see the term "free-threaded" to describe a class or a method. It seems to have a similar or identical meaning to "thread-safe".

两个词之间有区别吗?

推荐答案

在其他情况下可能还有其他含义,但是在我以前使用过的情况下,自由线程"表示它可以工作,或者在最少可以跨不同线程工作,而无需在公寓之间进行任何编组.

There may well be other things meant in other contexts, but in cases I've worked with in the past, "free threaded" means it works, or at least can work, across different threads without any marshalling between apartments.

相反,单元线程通过单独的全局"数据副本(因此当您考虑时不是真正的全局数据)来阻止不同的公寓",或者只允许一个线程在单元中运行,或者允许使用多个,但仍与使用其他公寓的公寓分开.

Apartment-threading in contrast blocks off different "apartments" with separate copies of "global" data (which hence isn't really global, when you think about it) and either allows only one thread to operate in the apartment, or allows several but which will still be separate from those using other apartments.

现在,由于单元模型自身提供了一些线程安全性,因此有关线程安全性的一些(但不是全部)顾虑消失了.设计为在单元模型中运行的一段代码将是线程安全的,但是部分或全部线程安全性来自单元模型.

Now, because the apartment model offers some thread-safety of its own, some (but not all) concerns about thread-safety go away. A piece of code that is designed to operate in an apartment model will be thread-safe, but some or all of that thread-safety is coming from the apartment model.

一个免费的线程代码段必须提供对其所声称的线程安全程度的完全保证.

A free threaded piece of code will have to provide full guarantees of whatever degree of thread-safety it is claiming itself.

这意味着它几乎与线程安全具有相同的含义,对于您无需考虑使用单元模型代码的线程安全的任何意图和目的,

Which means it pretty much does mean the same thing as thread-safe, for any intents and purposes where you don't also have to consider the thread-safety of the use of apartment-model code.

这篇关于“自由线程"与“自由线程"之间的区别在于:和“线程安全"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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