Skip to content

🟣 Concurrency interview questions and answers to help you prepare for your next software architecture and design patterns interview in 2025.

Notifications You must be signed in to change notification settings

Devinterview-io/concurrency-interview-questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

Top 21 Concurrency interview questions and answers in 2021.

You can check all 21 Concurrency interview questions here πŸ‘‰ https://devinterview.io/design/concurrency-interview-questions


πŸ”Ή 1. What is a Deadlock?

Answer:

  • A lock occurs when multiple processes try to access the same resource at the same time. One process loses out and must wait for the other to finish.

  • A deadlock occurs when the waiting process is still holding on to another resource that the first needs before it can finish.

So, an example:

Resource A and resource B are used by process X and process Y

  • X starts to use A.
  • X and Y try to start using B
  • Y 'wins' and gets B first
  • now Y needs to use A
  • A is locked by X, which is waiting for Y
Thread 1 Thread 2 

Lock1->Lock(); Lock2->Lock(); WaitForLock2(); WaitForLock1(); <-- Oops!

The best way to avoid deadlocks is to avoid having processes cross over in this way. Reduce the need to lock anything as much as you can. In databases avoid making lots of changes to different tables in a single transaction, avoid triggers and switch to optimistic/dirty/nolock reads as much as possible.

Source:Β stackoverflow.comΒ  Β 


πŸ”Ή 2. Explain the difference between Asynchronous and Parallel programming?

Answer:

When you run something asynchronously it means it is non-blocking, you execute it without waiting for it to complete and carry on with other things. Parallelism means to run multiple things at the same time, in parallel. Parallelism works well when you can separate tasks into independent pieces of work. Async and Callbacks are generally a way (tool or mechanism) to express concurrency i.e. a set of entities possibly talking to each other and sharing resources.

Take for example rendering frames of a 3D animation. To render the animation takes a long time so if you were to launch that render from within your animation editing software you would make sure it was running asynchronously so it didn't lock up your UI and you could continue doing other things. Now, each frame of that animation can also be considered as an individual task. If we have multiple CPUs/Cores or multiple machines available, we can render multiple frames in parallel to speed up the overall workload.

Source:Β stackoverflow.comΒ  Β 


πŸ”Ή 3. What is a Mutex?

Answer:

A Mutex is a mutually exclusive object. It acts as a gate keeper to synchronise two threads. When you have two threads attempting to access a single resource, the general pattern is to have the first block of code attempting access, to set the mutex before entering the code. When the second code block attempts access, it sees that the mutex is set and waits until the first block of code is complete (and un-sets the mutex), then continues.

Specific details of how this is accomplished obviously varies greatly by programming language.

Source:Β Stackoverflow.comΒ  Β 


πŸ”Ή 4. Is there any difference between a Binary Semaphore and Mutex?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 5. What is a Race Condition?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 6. Write a function that guarantees to never return the same value twice

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 7. Explain Deadlock to 5 years old

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 8. What is the meaning of the term β€œThread-Safe”?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 9. How much work should I place inside a lock statement?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 10. What is the difference between Concurrency and Parallelism?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 11. What's the difference between Deadlock and Livelock?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 12. What are some advantages of Lockless Concurrency?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 13. What is Green Thread?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 14. What is a Data Race?

πŸ‘‰πŸΌ Check all 21 answers


πŸ”Ή 15. What is Starvation?

πŸ‘‰πŸΌ Check all 21 answers



Thanks πŸ™Œ for reading and good luck on your next tech interview!
Explore 3800+ dev interview question here πŸ‘‰ Devinterview.io