Thread-safe versions of various common collection types in C #

Source: Internet
Author: User

In C # We often use a variety of collections, arrays, list,dictionary,stack, and so on, but these collections are non-thread-safe, when multithreading at the same time read and write these collections, it is possible to cause the data inside the confusion, For this reason, Microsoft has specifically provided another set of thread-safe versions (placed in the System.Collections.Concurrent namespace) from Net4.0.

There are all these:

When multiple threads concurrently access the collection, these classes should be used in place of the corresponding types in the System.Collections and System.Collections.Generic namespaces.

class description
Blockingcollection<t> Provides blocking and throttling capabilities for implementing a thread-safe collection of iproducerconsumercollection<t>.
Concurrentbag<t> Represents an unordered collection of thread-safe objects.
Concurrentdictionary<tkey, tvalue> Represents a thread-safe collection of key-value pairs that can be accessed concurrently by multiple threads.
Concurrentqueue<t> Represents a thread-safe FIFO (FIFO) collection.
Concurrentstack<t> Represents a thread-safe last-in-first-out (LIFO) collection.
Orderablepartitioner<tsource> Represents a specific way to split a sortable data source into multiple partitions.
Partitioner Provides common partitioning policies for arrays, lists, and enumerable items.
Partitioner<tsource> Represents a specific way to split a data source into multiple partitions.
Interface description
Iproducerconsumercollection<t> Defines a method that is used by the manufacturer/consumer to manipulate the thread-safe collection. This interface provides a uniform representation (for producer/consumer collections), thus higher level abstractions such as system.collections.concurrent.blockingcollection<t> can use the collection as the underlying storage mechanism.

Thread-safe versions of various common collection types in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.