实现:
c#实现线程安全的List,主要还是给夹锁。代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime;
using System.Text;
namespace Concurrent
{
/// <summary>
///
/// <typeparam name="T"></typeparam>
public class ConcurrentList<T> : IList<T>, ICollection<T>, IEnumerable<T>
{
List<T> _list;
// 摘要:
// 初始化 System.Collections.Generic.List<T> 类的新实例,该实例为空并且具有默认初始容量。
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public ConcurrentList()
{
_list = new List<T>();
}
//
// 摘要:
// 初始化 System.Collections.Generic.List<T> 类的新实例,该实例包含从指定集合复制的元素并且具有足够的容量来容纳所复制的元素。
//
// 参数:
// coll