zoukankan      html  css  js  c++  java
  • C# 内存理论与实践

    The C# Memory Model in Theory and Practice

    Sequential Execution with Locking

    Best Practices
    • All code you write should rely only on the guarantees made by the ECMA C# specification, and not on any of the implementation details explained in this article.
    • Avoid unnecessary use of volatile fields. Most of the time, locks or concurrent collections (System.Collections.Concurrent.*) are more appropriate for exchanging data between threads. In some cases, volatile fields can be used to optimize concurrent code, but you should use performance measurements to validate that the benefit outweighs the extra complexity.
    • Instead of implementing the lazy initialization pattern yourself using a volatile field, use the System.Lazy<T> and System.Threading.LazyInitializer types.
    • Avoid polling loops. Often, you can use a BlockingCollection<T>, Monitor.Wait/Pulse, events or asynchronous programming instead of a polling loop.
    • Whenever possible, use the standard .NET concurrency primitives instead of implementing equivalent functionality yourself.
  • 相关阅读:
    Android新手引导库推荐
    windbg 常调用指令
    通过Hook NtOpenProcess 函数实现反调试
    PE文件
    消息机制
    软件调试
    异常(2) --- 编译器对于SEH异常的拓展
    异常(1)
    等待对象
    进程与线程
  • 原文地址:https://www.cnblogs.com/itelite/p/4221956.html
Copyright © 2011-2022 走看看