- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我一直试图从我的一个程序中挤出更多的性能,并且正在阅读优先级和关联设置,我遇到了 Thread.BeginThreadAffinity
,它的文档说:
Notifies a host that managed code is about to execute instructions that depend on the identity of the current physical operating system thread.
我在我的程序中对此进行了测试,性能提高了大约 3-4%。据我了解,如果您的代码移动到不同的物理操作系统线程,它会失去亲和性设置,但是使用 Thread.BeginAffinity
它会留在同一个线程上,保持亲和性设置,因为我的是升高,我得到提高的性能。
它是这样工作的,还是我误解了 Thread.BeginAffinity
?
最佳答案
根据 msdn你是对的
Some hosts of the common language runtime, such as Microsoft SQL Server 2005, provide their own thread management. A host that provides its own thread management can move an executing task from one physical operating system thread to another at any time. Most tasks are not affected by this switching. However, some tasks have thread affinity - that is, they depend on the identity of a physical operating system thread. These tasks must inform the host when they execute code that should not be switched.
For example, if your application calls a system API to acquire an operating system lock that has thread affinity, such as a Win32 CRITICAL_SECTION, you must call BeginThreadAffinity before acquiring the lock, and EndThreadAffinity after releasing the lock.
Using this method in code that runs under SQL Server 2005 requires the code to be run at the highest host protection level.
关于c# - 线程.BeginThreadAffinity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11833120/
我一直试图从我的一个程序中挤出更多的性能,并且正在阅读优先级和关联设置,我遇到了 Thread.BeginThreadAffinity,它的文档说: Notifies a host that mana
Thread 类中的Thread.BeginThreadAffinity() 方法有什么用?如果您提供带有解释的示例示例,这将有助于我理解。 谢谢。 最佳答案 在 .NET 1.x 中,线程始终与操作
我是一名优秀的程序员,十分优秀!