Notes on the problem of concurrent computing 101

The problem

In concurrent applications , one of the problems to resolve is the synchronized access of a critical section typically accessing a shared resource.

Examples of this could be:

This problem can be reduced to the analysis in how the critical section is accessed and synchronized.

We will start with definitions.

Critical section

Critical section is any piece of code that has the possibility of being executed concurrently by more than one thread of the application and exposes any shared data or resources used by the application for access.

Parallel vs Concurrent

Synchronous vs Asynchronous

Problems when designing concurrent programs.

From educative.io Java Multithreading for Senior Engineering Interviews

On my own ,

Usually very hard to find bugs? Can you spot the bug below?

Some common problems with critical sections

DeadLock . Deadlocks occur when two or more threads aren’t able to make any progress because the resource required by the first thread is held by the second and the required resources by the second thread is held by the first.

Live-Lock. A live-lock occurs when two threads continuously react in response to the actions by the other thread without making any real progress.

Liveness Is the Ability of a program or an application to execute in a timely manner is called liveness. If a program experiences a deadlock then it’s not exhibiting liveness.

What approaches do we have to resolve the problems of concurrent access to a critical section?

Mutual exclusion ! First resolved by Edsger W. Dijkstra

What are the basic data structures to handle mutual exclusion?

In summary ,

Java concurrency control mechanisms

Java’s util.concurrent package provides several classes and language constructs that can be used for solving everyday concurrency problems and should always be preferred than reinventing the wheel.

Other useful Java objects when working with concurrent applications.

Java No No’s

Other related concepts.

References

Coffee lover (serious espresso drinker)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store