DEV Community

Calzy
Calzy

Posted on

Concurrency

Concurrency is the simultaneous execution of several instruction sequences. It occurs in the operating system when many process threads are executing concurrently. Threads of running processes constantly communicate with one another via shared memory or message forwarding. Through this article, I am going to discuss several key points about concurrency.

One of the most common problem occurring in concurrency is the producer-consumer problem. Before we can understand the Producer-Consumer Problem, we must first define the terms Producer and Consumer.

  • In an operating system, a Producer is a process that may generate data or items.
  • The Consumer is a Process that can consume the data/item created by the Producer.
  • A memory buffer is shared by both the Producer and the Consumer. This buffer is a certain size of memory in the system that is utilized for storing. The producer produces the data into the buffer and the consumer consumes the data from the buffer.

Illustration
Source: Scaler

The Producer-Consumer dilemma is a well-known synchronization issue in computer systems. The problem is as follows: there is a fixed-size buffer, as well as a Producer and a Consumer process. The Producer operation generates an item and inserts it into the shared buffer. The Consumer process "consumes" objects that are in the shared buffer.

Other concept of concurrency is Mutual Exclusion. Mutex, or mutual exclusion, is a unit of code that prevents concurrent access to shared resources. Mutual exclusion is a concurrency control characteristic that is implemented to avoid race problems. In plain terms, it is a condition in which a thread of execution is never involved in a crucial part at the same time as another thread of execution that is also utilizing the critical section. This crucial part can be characterized as a time when the thread of execution accesses a shared resource, such as a data object, which several concurrent threads may seek to change.

Another concurrency concept is Semaphores. Semaphores are synchronization mechanisms that are used in computer systems to synchronize the activity of various processes. They are used to ensure mutual exclusion, avoid race situations, and establish process synchronization.

There is also Starvation concept in concurrency. Starvation is an issue that happens when high priority processes continue to run while low priority processes are halted indefinitely. A continual stream of higher-priority processes in a densely loaded computer system can prevent a low-priority operation from ever receiving the CPU. In times of scarcity, high priority activities consume all available resources. Aging can help alleviate the problem of famine. The priority of long waiting processes is steadily elevated as people age.

Concurrency is governed by a number of principles. Some of the key concepts and approaches connected to concurrency are the producer-consumer issue, mutual exclusion, semaphore, and starvation.

Top comments (0)