Dataset Viewer
Auto-converted to Parquet Duplicate
answer
stringclasses
3 values
question
stringclasses
3 values
race_paths
listlengths
2
2
source_code
stringclasses
3 values
shared_state
listlengths
2
2
execution_result
stringclasses
3 values
concurrency_mechanism
stringclasses
3 values
synchronization_boundaries
listlengths
3
3
Both calls can run loader because each releases _lock before invoking it. When they attempt publication, compare_and_set checks the current version and replaces the entry only if it still equals the version each call read. The first successful call increments the version; the other then sees a mismatch and returns Fals...
If two refresh calls read the same entry version before either loader finishes, can both publish their results? What work may still be duplicated?
[ "Two refresh calls can snapshot the same version and run their loaders concurrently. The first successful compare_and_set advances the version; the other call is rejected and returns False.", "Because the loader runs outside the lock, its computation can be based on a value that another refresh has since replaced...
import threading class VersionedCache: def __init__(self): self._entries = {} self._lock = threading.Lock() def compare_and_set(self, key, expected_version, new_value): with self._lock: current = self._entries.get(key) if current is None or current[1] != expect...
[ "_entries maps each key to a (value, version) pair; its reads and writes in these methods are protected by _lock.", "The entry version is shared coordination state: compare_and_set reads it and increments it when a replacement succeeds." ]
refresh returns False if the key is absent when it takes its snapshot, or if its computed result loses the version check. It returns True when its result is stored and the entry version is incremented by one.
A mutex makes the version check and entry replacement one critical section. refresh uses an optimistic pattern: it reads a value and version under the lock, computes outside the lock, then conditionally publishes only if the version is unchanged.
[ "The first with self._lock block in refresh protects reading the entry and its version.", "The with self._lock block in compare_and_set protects the version comparison and replacement as one indivisible operation relative to other accesses using this instance's lock.", "loader(value) runs outside the lock, so c...
invalidate increments the key's epoch and removes its cached value while holding the same lock used by publication. When the earlier load finishes, it compares the current epoch with its captured epoch under the lock. If invalidation has occurred, the epochs differ, so load_and_publish returns False without storing tha...
What happens if invalidate runs after load_and_publish captures the key's epoch but before its loader finishes? Can two loads from the same epoch both publish?
[ "A load can capture an epoch, then an invalidation can increment that epoch and remove the entry before the load finishes. The later publication check rejects the old load, preventing it from restoring a value from before the invalidation.", "Two loads can capture the same epoch and finish in either order. Since ...
import threading class CacheWithInvalidationEpochs: def __init__(self): self._values = {} self._epochs = {} self._lock = threading.Lock() def invalidate(self, key): with self._lock: self._epochs[key] = self._epochs.get(key, 0) + 1 self._values.pop(key, ...
[ "_epochs maps keys to generation counters; invalidate increments a counter, and load_and_publish reads it before and after loading.", "_values maps keys to cached values; invalidate removes entries and load_and_publish may insert them, with those operations protected by _lock." ]
If the key's epoch is unchanged when publication is attempted, the value is stored and load_and_publish returns True. If the epoch changed, the value is not stored and the method returns False; the caller can use that result to decide whether to retry or discard the loaded value.
A per-key epoch acts as a generation token. A loader snapshots the token before doing work outside the lock, then checks it before publishing. Invalidation advances the token, preventing a load from an earlier generation from repopulating the cache.
[ "The lock in invalidate protects incrementing the key's epoch and removing its cached value as one operation.", "The first lock block in load_and_publish protects the epoch snapshot.", "The final lock block in load_and_publish protects comparing the current epoch with the snapshot and, when they match, storing ...
The lock serializes the cache lookup and the decision to create or join a per-key flight. The leader runs loader outside the lock, so unrelated keys—and other code using the cache—are not blocked by the loader itself. Callers that find an existing flight wait on its event. On success, the leader stores the value and pl...
For concurrent calls to get_or_load with the same key, which work is serialized, and what do waiting callers observe if the loader raises an exception?
[ "If several callers miss the same key concurrently, the first caller to insert a flight becomes leader; the others observe that flight and wait rather than invoking loader themselves.", "After a failed flight is removed, a new caller can create a new flight while callers from the failed flight are still waking an...
import threading class _Flight: def __init__(self): self.event = threading.Event() self.value = None self.error = None class Cache: def __init__(self): self._values = {} self._flights = {} self._lock = threading.Lock() def get_or_load(self, key, loader): ...
[ "_values maps keys to cached values; reads and writes in this method occur under _lock.", "_flights maps keys to shared _Flight objects; the map is accessed under _lock, while each flight's value, error, and event communicate the outcome to its waiters." ]
For a successful load, the value is cached and returned by the leader and callers waiting on that flight. If loading raises an Exception, the leader re-raises it and waiters raise the recorded exception; the failed flight is removed, so a subsequent call may try loading again.
A mutex protects the cache and per-key in-flight map, while an event lets callers for the same missing key share the leader's result or exception. This coalesces concurrent loads for a key while the flight remains registered.
[ "The with self._lock blocks protect checking and updating _values and looking up, inserting, or removing entries in _flights.", "flight.event.wait() blocks followers until the leader has stored either the result or the exception and signaled completion.", "loader() runs outside the mutex; its execution is not s...

Distributed Cache Concurrency Control Code Understanding Dataset

This dataset contains distributed cache source code excerpts related to locks, atomic operations, concurrent updates, and request coalescing, paired with questions and answers about synchronization boundaries, shared state, and potential race paths. It helps models analyze concurrency mechanisms from source code and explain their effects on cache state, request responses, and other execution outcomes, making it suitable for code supervised fine-tuning and distributed cache code understanding. Dataset size and licensing terms are provided on the product page.

Technical Specifications

Field Type Description
answer string An explanation of the concurrency logic based on the source code that addresses the question.
question string A question about the source code, such as identifying synchronization boundaries, shared state, or potential race paths.
race_paths array Potential races caused by concurrent interleavings, insufficient synchronization scope, or shared state access, together with their possible effects.
source_code string A distributed cache source code excerpt involving locks, atomic operations, concurrent updates, request coalescing, or related mechanisms.
shared_state array Cache state, flags, counters, or related data that may be accessed or modified by multiple execution paths.
execution_result string The resulting cache state, request response, or other observable outcome after the relevant concurrent execution.
concurrency_mechanism string The locks, atomic operations, request coalescing, or other concurrency controls used in the source code and their purposes.
synchronization_boundaries array The locked regions, scope of atomic operations, or other synchronization boundaries, with the state or operations each protects.

Compliance Statement

Authorization TypeCC-BY-NC-SA 4.0 (Attribution–NonCommercial–ShareAlike)
Commercial UseRequires exclusive subscription or authorization contract (monthly or per-invocation charging)
Privacy and AnonymizationNo PII, no real company names, simulated scenarios follow industry standards
Compliance SystemCompliant with China's Data Security Law / EU GDPR / supports enterprise data access logs

Source & Contact

contact@mobiusi.com

Downloads last month
20