Language-Level Concurrency and Multithreading Questions
Per-language and per-runtime concurrency: the threading and async APIs each language provides (goroutines and channels in Go, threads and executors in Java, async/await runtimes, C++ std::thread and atomics), each language's memory model, and the idioms for coordinating shared state safely in that language. Covers choosing and using a language's concurrency primitives correctly; OS-level scheduling, synchronization theory, and deadlock internals live in Operating Systems & Systems Programming.
Analyze the following Java code used in a service. Explain the control flow, identify potential race conditions or thread-safety issues, propose two possible fixes (with brief code sketches or descriptions), and describe how you would document the concurrency behavior and expectations for future developers.
public class CounterService {
private int counter = 0;
public void increment() {
counter += 1;
}
public int getAndReset() {
int current = counter;
counter = 0;
return current;
}
}
Describe a situation where you found a subtle race condition or concurrency bug in a multi-threaded or async project. Explain how you reproduced the issue, debugging tools or logging you used, the root cause (ordering, shared state), and the fix you implemented. How did you ensure the fix covered all relevant code paths?
Design a thread-safe shared counter in Java where multiple threads increment and read the value. Provide a concise implementation using idiomatic concurrency primitives, explain why it's correct, and discuss performance implications under high contention.
Explain how a data race in a multi-threaded cache can lead to intermittent corruption. Provide a concise code example showing a read-modify-write race, explain why the problem appears intermittently and how different timings expose it, and propose both locking and lock-free fixes with their trade-offs.
Design and implement (or describe implementation) of a thread-safe LRU cache in Java that handles null keys/values by rejecting them, works with capacity=1 and capacity=N, and resists concurrent get/put races. Explain your locking strategy, potential bottlenecks, and how to test boundary behavior under concurrency.
Unlock Full Question Bank
Get access to all 7 Language-Level Concurrency and Multithreading interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.