Concurrent Data Structures

Thread-safe data structures: concurrent hash maps, skip lists, queues, stacks, read-write locks, lock-free algorithms, and compare-and-swap patterns.

  • JSON8,236 B
  • YAML5,941 B · −28%
  • TOON5,396 B · −34%

Data structures designed for concurrent access: striped hash maps, skip lists, lock-free queues and stacks, read-write locks, compare-and-swap and safe memory reclamation with hazard pointers and epochs, each with implementations, contention and notes.

Use it when

  • You are choosing a thread-safe container or synchronization primitive.
  • You are reading about lock-free design.

Watch out for

  • Lock-free structures are difficult to get right; prefer well-tested library implementations.
  • Performance depends on contention and hardware memory ordering.

The data

Structures

NameTypeDescriptionImplementationsContentionNotesOperations
Concurrent Hash Map (Striped/Segmented)Lock-basedHash map with segmented locking: different buckets can be locked independently, allowing concurrent access to different segments
  • Java ConcurrentHashMap (striped, CAS-based)
  • C++ tbb::concurrent_unordered_map
  • .NET ConcurrentDictionary
Low (only on same segment)Java 8+ uses CAS + synchronized on individual bins; read operations often lock-freenull
Concurrent Skip ListLock-free (optimistic)Probabilistic balanced search structure; uses CAS for lock-free insertion/deletion with high probability
  • Java ConcurrentSkipListMap/Set
  • C++ concurrent_skiplist
nullBetter concurrency than balanced trees (no rebalancing); used as concurrent sorted mapO(log n) expected for search/insert/delete
Lock-Free Queue (Michael-Scott)Lock-freeLinked-list queue using CAS on head and tail pointers; multiple producers/consumers without locks
  • Java ConcurrentLinkedQueue
  • C++ boost::lockfree::queue
nullMay have memory reclamation issues (ABA problem); use hazard pointers or epoch-based reclamation in productionO(1) amortized enqueue/dequeue
Concurrent Stack (Treiber Stack)Lock-freeLinked-list stack using CAS on top pointer; simple but can have contention on single atomic variable
  • C++ tbb::concurrent_bounded_queue (similar)
  • Java ConcurrentLinkedDeque
nullHigh contention under heavy concurrent use; consider combining techniques or elimination backoffO(1) push/pop
Read-Write LockLock-based (shared/exclusive)Allows multiple concurrent readers OR one exclusive writer; optimizes read-heavy workloads
  • Java ReentrantReadWriteLock
  • C++ shared_mutex (C++17)
  • POSIX pthread_rwlock_t
nullRisk of writer starvation under heavy read load; use StampedLock (Java) or upgradeable read locksRead: O(1), Write: O(1) + potential writer starvation
Compare-And-Swap (CAS)Atomic primitiveAtomically: if (location == expected) location = new_value; return success/failure. Foundation of all lock-free algorithms
  • Java Unsafe.compareAndSwap*()
  • C++ std::atomic<T>::compare_exchange_weak/strong
  • x86 CMPXCHG instruction
nullCAS loop pattern: while (!CAS(loc, expected, new)) expected = *loc; ABA problem requires versioned pointers or hazard pointersO(1) atomic
Hazard PointersMemory reclamationLock-free memory reclamation technique: threads announce which nodes they're accessing; nodes not in any hazard list can be safely freed
  • Boost.Lockfree
  • Folly (Facebook)
  • DPDK
nullSolves ABA and use-after-free in lock-free structures; bounded memory overhead (O(threads × hazard_slots))O(1) publish/unpublish
Epoch-Based ReclamationMemory reclamationThreads announce their epoch; retired nodes are freed when all threads have moved past the epoch when node was retired
  • Seastar
  • Folly
  • RCU (Read-Copy-Update) in Linux kernel
nullLower overhead than hazard pointers for read-heavy workloads; used extensively in kernel RCUO(1) enter/exit epoch

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
structuresnamestringConcurrent Hash Map (Striped/Segmented)
structurestypestringLock-based
structuresdescriptionstringHash map with segmented locking: different buck…
structuresimplementationsarray[3 items]
structurescontentionstringLow (only on same segment)
structuresnotesstringJava 8+ uses CAS + synchronized on individual b…
structuresoperationsstringO(log n) expected for search/insert/delete

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.com/api/dataset/concurrent-data-structures?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/concurrent-data-structures.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • concurrency
  • lock-free
  • compare-and-swap
  • concurrent-hash-map
  • concurrent-queue
  • read-write-lock
  • atomic

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets