简体   繁体   English

coreclr中的Thread.Yield()

[英]Thread.Yield() in coreclr

In .NET Thread class has static method Yield. 在.NET Thread类中有静态方法Yield。
I see that method in coreclr implementation of Thread . 我在Thread的coreclr实现中看到了这个方法。
But documentation doesn't contain that Method description. 但是文档不包含Method描述。
Also .NET CLI (dotnet build) cant compile code with that method invocation. 此外,.NET CLI(dotnet build)无法使用该方法调用编译代码。
Why? 为什么?

upd UPD
runtime: 1.0.0-rc1-update1 coreclr x64 darwin 运行时: 1.0.0-rc1-update1 coreclr x64 darwin

project.json project.json

{
    "version": "1.0.0-*",
    "compilationOptions":
    {
        "emitEntryPoint": true
    },
    "dependencies":
    {
        "NETStandard.Library": "1.0.0-rc2-*",
        "System.Threading": "4.0.11-rc3-*"
    },

    "frameworks": {
        "dnxcore50": {}
    }
}

upd2 UPD2
I'm not going to use Thread.Yield(); 我不打算使用Thread.Yield();
I was just wondering why some framework features are absent in coreclr. 我只是想知道为什么coreclr中缺少某些框架功能。

You are looking at the wrong file, the correct one is in the corefx depository. 您正在查看错误的文件,正确的文件位于corefx存储库中。 This one . 这个

Note that it is special, it only contains declarations. 请注意,它是特殊的,它只包含声明。 It is the reference assembly , the one that your compiler uses. 它是引用程序集 ,是编译器使用的程序集。 As you can tell, it does not have a Yield() method so a guaranteed eek! 你可以告诉它,它没有Yield()方法所以保证eek! from the compiler. 来自编译器。 Distinguishing the reference assembly from the implementation assembly in the GAC is something that happened a long time ago, have a look-see at the C:\\Program Files (x86)\\Reference Assemblies directory on a Windows machine. 将参考程序集与GAC中的实现程序集区分开来是很久以前发生的事情,请查看Windows计算机上的C:\\ Program Files(x86)\\ Reference Assemblies目录。

The exact reasons that a member or type is omitted is not always obvious. 省略成员或类型的确切原因并不总是显而易见的。 From what I've seen, factors that play a role are: 从我所看到的,发挥作用的因素是:

  1. The type or member is simply not supported by the .NETCore version of the CLR. CLR的.NETCore版本根本不支持类型或成员。 Originally designed to be a small version of the CLR that was targeted to mobile devices and easy to download, Silverlight is the most recognizable member of that family. Silverlight最初设计为针对移动设备的小型CLR,易于下载,是该系列中最知名的成员。 With the additional feature that small also makes it easier to port the CLR to another platform, .NETCore served as the bootstrap of CoreCLR since making it run on Linux and OSX was a strong goal. 由于使用较小的附加功能也可以更轻松地将CLR移植到另一个平台,因此.NETCore可以作为CoreCLR的引导程序,因为它可以在Linux和OSX上运行,这是一个强大的目标。 AppDomain is a good example. AppDomain就是一个很好的例子。

  2. It might not yet have been implemented on every OS or it is in the wrong .NETStandard profile. 它可能尚未在每个操作系统上实现,或者它位于错误的.NETStandard配置文件中。 Keeping it out of the reference assembly is a very simple way to prevent a program from accidentally using it and trigger a possibly very hard to diagnose runtime exception. 将其保留在引用程序集之外是一种非常简单的方法,可以防止程序意外使用它并触发可能非常难以诊断的运行时异常。

  3. The .NET team wanted to deprecate it, CoreFx was a terrific opportunity to cut some dead wood or pursue a new best practice. .NET团队想要弃用它,CoreFx是削减一些死木或追求新的最佳实践的绝佳机会。 Lots of examples of this, String.GetEnumerator() is one that usually stumps programmers, justification I heard from a team member that it isn't efficient enough. 很多这样的例子,String.GetEnumerator()通常会让程序员难以接受,我从团队成员那里听到的理由是它不够高效。 Obsolete .NET 1.x classes like ArrayList are more obvious. 像ArrayList这样过时的.NET 1.x类更为明显。

I can't be sure why Thread.Yield() fell on the floor, but it is used heavily in the CoreCLR implementation (YieldProcessor and __SwitchToThread) so high odds that it fits bullet 3. Microsoft has been pushing hard to make their operating systems and frameworks more friendly to mobile devices, the kind of platform where they have not competed well. 我不能确定为什么Thread.Yield()落在了地板上,但它在CoreCLR实现(YieldProcessor和__SwitchToThread)中使用得很多,因此很有可能它适合子弹3.微软一直在努力制造他们的操作系统和框架对移动设备更友好,这是一种他们没有很好竞争的平台。 Threads are definitely not friendly. 线程绝对不友好。

Good odds that they want you to use Task.Yield() instead. 很有可能他们希望你使用Task.Yield()代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM