gpt4 book ai didi

c# - NET 4.0 SpinWait 方法与 4.0 之前的 SpinWait() 有何不同?

转载 作者:行者123 更新时间:2023-11-30 13:38:44 25 4
gpt4 key购买 nike

MSDN "Thread-Safe Collections .NET Framework 4"状态:

"Some of the concurrent collection types use lightweight synchronization mechanisms such as SpinLock, SpinWait, SemaphoreSlim, and CountdownEvent, which are new in the .NET Framework 4"

虽然 MSDN 网站告诉我们 SpinWaitwas was available as far as .NET 1.1而另一篇 MSDN 文章 starts SpinWaitwas from .NET 4.0

好吧,好奇心来自 Lee Grissom 的评论以回答 What is the difference between SynchronizedCollection and the other concurrent collections? :

"@Matt, the .NET4 concurrent classes use SpinWait objects to address thread-safety instead of Monitor.Enter/Exit (aka Critical section)?"

以及第一个 NSDN 引述指出 SpinWait 是 .NET 4.0 的新内容

所以,它是不​​是新的?
如果是新的,那又如何呢?

最佳答案

System.Threading.SpinWait structure 被引入到 .NET 4 中。System.Threading.Thread.SpinWait method 自 .NET 1.0 以来一直存在。

来自 SpinWait 结构的文档:

SpinWait is not generally useful for ordinary applications. In most cases, you should use the synchronization classes provided by the .NET Framework, such as Monitor. For most purposes where spin waiting is required, however, the SpinWait type should be preferred over the SpinWait method.

请注意在大多数情况下您不应该使用它们中的任何一个的部分:)

关于c# - NET 4.0 SpinWait 方法与 4.0 之前的 SpinWait() 有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15110860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com