沒有,但你可以通過引用FSharp創建一個線程安全的集合。 Core.dll並使用Microsoft.FSharp.Collections。
只是換行使用interlocked.CompareExhchange添加和刪除。
性能因組的大小而異。但你應該能夠處理數十萬個項目。
這會處理大量的線程讀取和寫入設置。
也把「鎖」(不是一個真正的鎖,原子操作的只是面積)大約是字裏行間的一切:
initialSet = sharedSet;
和
做=(initialSet == Interlocked.CompareExchange(參照sharedSet,newSet,initialSet));
FSharpSet<MyClass> _myItems;
InterLockedSetAdd(ref _myItems, Item);
public static void InterLockedSetAdd<T>(ref FSharpSet<T> sharedSet, T item)
{
FSharpSet<T> initialSet;
FSharpSet<T> newSet;
var spin = new SpinWait();
bool done = false;
while (!done)
{
initialSet = sharedSet;
newSet = sharedSet.Add(item);
done = (initialSet == Interlocked.CompareExchange(ref sharedSet, newSet, initialSet));
if (!done) spin.SpinOnce();
}
}
的可能重複:http://stackoverflow.com/questions/4306936/how-to-implement-concurrenthashset-in-net – rossipedia