Bird
0
0
LLDsystem_design~10 mins

Concurrency considerations in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to acquire a lock before accessing shared data.

LLD
lock.[1]()  # Acquire the lock before critical section
Drag options to blanks, or click blank then click option'
Aacquire
Brelease
Cwait
Dnotify
Attempts:
3 left
💡 Hint
Common Mistakes
Using release() before acquire() causes errors.
Confusing wait() or notify() with lock acquisition.
2fill in blank
medium

Complete the code to safely release the lock after the critical section.

LLD
try:
    # critical section code
    pass
finally:
    lock.[1]()  # Release the lock
Drag options to blanks, or click blank then click option'
Await
Bacquire
Crelease
Dnotify
Attempts:
3 left
💡 Hint
Common Mistakes
Calling acquire() again instead of release().
Forgetting to release the lock causing deadlocks.
3fill in blank
hard

Fix the error in the code to avoid race conditions when updating a shared counter.

LLD
def increment():
    global counter
    [1]  # Missing synchronization here
    counter += 1
    lock.release()
Drag options to blanks, or click blank then click option'
Alock.notify()
Block.release()
Clock.wait()
Dlock.acquire()
Attempts:
3 left
💡 Hint
Common Mistakes
Releasing the lock before acquiring it.
Using wait() or notify() incorrectly.
4fill in blank
hard

Fill both blanks to implement a thread-safe queue using locks.

LLD
def enqueue(item):
    [1]  # Acquire lock
    queue.append(item)
    [2]  # Release lock
Drag options to blanks, or click blank then click option'
Alock.acquire()
Block.release()
Clock.wait()
Dlock.notify()
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping acquire and release calls.
Using wait() or notify() instead of acquire/release.
5fill in blank
hard

Fill all three blanks to implement a safe read-modify-write operation with locks.

LLD
def update_value(key, delta):
    [1]  # Acquire lock
    current = data.get([2], 0)
    data[[3]] = current + delta
    lock.release()
Drag options to blanks, or click blank then click option'
Alock.acquire()
Bkey
Dlock.release()
Attempts:
3 left
💡 Hint
Common Mistakes
Not acquiring the lock before reading and writing.
Using different variables for key in get and set.