This question evaluates knowledge of concurrent programming and thread-safety, including the choice of in-memory data structures for a key–value store and synchronization techniques that ensure atomic put/get/delete operations without internal corruption.
You are working on infrastructure for an AI platform. Inside a single process, many worker threads need to share a simple in-memory key–value store; any thread can concurrently read, write, or delete keys.
Design and discuss a thread-safe key–value store class with the following requirements:
put(key, value)
: insert or overwrite the value for
key
.
get(key)
: return the current value for
key
, or
null
/
None
if absent.
delete(key)
: remove
key
if it exists.
Answer the following sub-questions:
dict
). How would you implement your chosen synchronization strategy there? Describe or sketch the implementation of
put
,
get
, and
delete
.
Login required