如何为NET 4.0 SpinWait方法不同pre-4.0 SpinWait()?何为、不同、方法、NET

2023-09-03 21:55:07 作者:▼白色的影子

MSDN 线程安全的集合.NET框架4规定:

一些并发集合类型的使用轻量级   同步机制,如自旋锁, SpinWait    SemaphoreSlim 和 CountdownEvent ,该是新的.NET   框架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是提供尽可能.NET 1.1 而另一MSDN文章的开始SpinWaitwas从.NET 4.0

while MSDN website tells that SpinWaitwas was available as far as .NET 1.1 while another MSDN article starts SpinWaitwas from .NET 4.0

那么,好奇心是从评论由李格里索姆回答 SynchronizedCollection和其他并发收集之间的区别是什么?:

Well, the curiosity is from the comment by Lee Grissom to answer What is the difference between SynchronizedCollection and the other concurrent collections?:

@马特,该.NET4并发类使用 SpinWait 反对地址   线程安全的,而不是Monitor.Enter /退出(又名临界区)?

"@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

as well as first NSDN quote stating that SpinWait is new to .NET 4.0

那么,是不是新的或不? 如果新的又如何?

So, is it new or not? And if new then how?

推荐答案

该结构 System.Threading.SpinWait 是一个新的.NET 4.0。该方法 System.Threading.Thread.SpinWait()的存在,因为.NET 1.0。

The struct System.Threading.SpinWait is new to .NET 4.0. The method System.Threading.Thread.SpinWait() exists since .NET 1.0.

注意 System.Threading.SpinWait 内部调用 System.Threading.Thread.SpinWait()。更多详情请参见并发编程在Windows由乔·达菲(第14章,节旋转等待)。

Note that System.Threading.SpinWait internally calls System.Threading.Thread.SpinWait(). For further details see "Concurrent Programming On Windows" by Joe Duffy (chapter 14, section "Spin Waiting").