高级C#:并发集合与线程安全

高级C#:并发集合与线程安全

“线程安全”类是其成员免受一个线程被另一线程打断这类情况的类。标准.NET集合类型不是线程安全的,这可能导致一系列问题,包括竞争条件,数据损坏以及现代多线程应用程序中的意外异常。在本课程中,讲师Walt Ritscher演示了如何使用线程安全的并发集合跨线程共享数据并构建更具可伸缩性的应用程序。Walt使用实际示例概述了在多线程应用程序中可能遇到的问题,并解释了为什么并发集合能够很好地处理多个线程。他探讨了如何使用ConcurrentDictionary类,包括如何更新ConcurrentDictionary中的数据。另外,了解生产者-消费者模式及其与并发集合类型的关系,如何使用BlockingCollection(线程安全的集合类)等等。

课程信息

  • 英文名称:Advanced C#: Thread-Safe Data with Concurrent Collections

  • 时长:1小时39分

  • 字幕:英语

课程目录

  1. Thread-safe data with concurrent collections
  2. What you should know
  3. How to access the sample code on GitHub
  4. Collections and threads
  5. Use Queue with single thread
  6. Use Queue with multiple threads
  7. Debug the Queue multiple-thread problem
  8. Re-implement the sample with custom class
  9. Examine the ExampleQueue code
  10. Rewrite the code to support thread locks
  11. Use a lock statement and mutex to make thread-safe
  12. Why locking is not a good solution
  13. How the concurrent collections are better
  14. Compare standard and concurrent collections
  15. Categories of collections
  16. Create a dictionary
  17. Use TryAdd to add an item
  18. Use TryRemove to remove an item
  19. The GetOrAdd method to get or add an item
  20. Review the updated example application
  21. Potential problems with updating an item
  22. Use TryUpdate to update dictionary value
  23. Use a while loop with TryUpdate
  24. Use the AddOrUpdate method
  25. Why ICollection and other interfaces are not thread-safe
  26. Inspect your APIs for ICollection usage
  27. Overview of the producer-consumer collections
  28. Work with ConcurrentQueue
  29. Work with the ConcurrentStack
  30. Work with the ConcurrentBag
  31. Understand the BlockingCollection
  32. Use the BlockingCollection with ConcurrentQueue
  33. Use the CompleteAdding method
  34. Use other collections with BlockingCollection
  35. Read items with multiple consumers
  36. Create items with multiple producers
  37. Next steps

评论