문제

Besides the well known data Structure which can be used in Multi-Threaded programs such as Concurrent Stack, Concurrent Queue, Concurrent List, Concurrent Hashing. Are there any other lesser know but useful Data Structures which can be used in parallel/Multi-Threaded programming.

Even if they are some different versions of above listed data structures with some optimization, then kindly do share.

Please do include some references.

Edit: Will keep listing what I find

1) ConcurrentCuckooHashing (Optimized version of ConcurrentHashing)

2) ConcurrentSkipList

도움이 되었습니까?

해결책

I will try to answer with examples from JDK, if you do not mind:

Lists:

  • CopyOnWriteArrayList is a list that achieves thread-safe usage by recreating backing array each time the list is modified;
  • Lists returned by Collections.synchronizedList() are thread-safe as they include exclusive locking for most operations (iteration over is an exception);
  • ArrayBlockingQueue. Queue that has a fixed size and blocks when there's nothing to pull out or no space to push in;
  • ConcurrentLinkedQueue is a lock-free queue based on Michael-Scott algorithm;
  • Concurrent stack, based on Treiber algorithm. Surprisingly, I didn't find that in JDK;

Sets:

  • Sets, returned by factory Collections.newSetFromMap() with a backing ConcurrentHashMap. With these sets you can be sure that its iterators is not prone to ConcurrentModificationException, and they use a striping technique for locking it - locking all set is not neccesary to perform some operations. For example, when you want to add element, only the part of the set determined by element hashCode() will be locked;
  • ConcurrentSkipListSet. The thread-safe set based on a Skip List data structure;
  • Sets, returned by Collections.synchronizedSet(). All points written about similar lists are applicable here.

Maps:

  • ConcurrentHashMap which I already mentioned and explained. Striping is based on item keys;
  • ConcurrentSkipListMap. Thread-safe map, based on skip list;
  • Maps, returned by Collections.synchronizedMap(). All points written about similar lists and maps are applicable here.

These were more or less standard data structures intended for multithreaded usage, which should be enough for most practical tasks. I also found some links you may find useful:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top