[英]How is NET 4.0 SpinWait method different to pre-4.0 SpinWait()?
MSDN "Thread-Safe Collections .NET Framework 4" states: MSDN “线程安全集合.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"
“一些并发集合类型使用轻量级同步机制,如SpinLock , SpinWait , SemaphoreSlim和CountdownEvent ,它们是.NET Framework 4中的新增功能”
while MSDN website tells that SpinWaitwas was available as far as .NET 1.1 while another MSDN article starts SpinWaitwas from .NET 4.0 虽然MSDN网站告诉SpinWaitwas可用于.NET 1.1,而另一篇MSDN文章从.NET 4.0启动SpinWaitwas
Well, the curiosity is from the comment by Lee Grissom to answer What is the difference between SynchronizedCollection and the other concurrent collections? 好吧,好奇心来自Lee Grissom的评论,以回答SynchronizedCollection和其他并发集合之间的区别是什么? :
:
"@Matt, the .NET4 concurrent classes use
SpinWait
objects to address thread-safety instead of Monitor.Enter/Exit (aka Critical section)?"“@Matt,.NET4并发类使用
SpinWait
对象来解决线程安全而不是Monitor.Enter / Exit(又称Critical部分)?”
as well as first NSDN quote stating that SpinWait
is new to .NET 4.0 以及第一个NSDN引用声明
SpinWait
是.NET 4.0的新手
So, is it new or not? 那么,它是新的还是不是?
And if new then how? 如果新的那么如何?
The System.Threading.SpinWait
structure was introduced into .NET 4. The System.Threading.Thread.SpinWait
method has been present since .NET 1.0. System.Threading.SpinWait
结构被引入.NET 4.自.NET 1.0以来, System.Threading.Thread.SpinWait
方法已经存在。
From the docs for the SpinWait
structure: 来自
SpinWait
结构的文档:
SpinWait is not generally useful for ordinary applications.
SpinWait通常不适用于普通应用程序。 In most cases, you should use the synchronization classes provided by the .NET Framework, such as Monitor.
在大多数情况下,您应该使用.NET Framework提供的同步类,例如Monitor。 For most purposes where spin waiting is required, however, the
SpinWait
type should be preferred over theSpinWait
method.但是,对于需要旋转等待的大多数目的,
SpinWait
类型应优先于SpinWait
方法。
Note the part that says you shouldn't be using either of them in most cases :) 请注意,在大多数情况下,您不应该使用其中任何一个的部分:)
The struct System.Threading.SpinWait
is new to .NET 4.0. struct
System.Threading.SpinWait
是.NET 4.0的新增功能。 The method System.Threading.Thread.SpinWait()
exists since .NET 1.0. System.Threading.Thread.SpinWait()
方法自.NET 1.0以来就存在。
Note that System.Threading.SpinWait
internally calls System.Threading.Thread.SpinWait()
. 请注意,
System.Threading.SpinWait
内部调用System.Threading.Thread.SpinWait()
。 For further details see "Concurrent Programming On Windows" by Joe Duffy (chapter 14, section "Spin Waiting"). 有关详细信息,请参阅Joe Duffy撰写的“Windows上的并发编程”(第14章“旋转等待”一节)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.