Concurrency

 Concurrency:

  • Concurrency in Operating System refers to the execution of several programs at the same time. It takes place in OS when multiple processes are executing in parallel. It is the execution of processes to provide an impression of a synchronous computation.

  • Principles of Concurrency

    Today's technology, like multi-core processors and parallel processing, allows multiple processes and threads to be executed simultaneously. Multiple processes and threads can access the same memory space, the same declared variable in code, or even read or write to the same file.

    The amount of time it takes a process to execute cannot be simply estimated, and you cannot predict which process will complete first, enabling you to build techniques to deal with the problems that concurrency creates.

  • Interleaved and overlapping processes are two types of concurrent processes with the same problems. It is impossible to predict the relative speed of execution, and the following factors determine it:

    1. The way operating system handles interrupts
    2. Other processes' activities
    3. The operating system's scheduling policies
  • Problems in Concurrency

    There are various problems in concurrency. Some of them are as follows:

    1. Locating the programming errors

    It's difficult to spot a programming error because reports are usually repeatable due to the varying states of shared components each time the code is executed.

    2. Sharing Global Resources

    Sharing global resources is difficult. If two processes utilize a global variable and both alter the variable's value, the order in which the many changes are executed is critical.


  • 3. Locking the channel

  • It could be inefficient for the OS to lock the resource and prevent other processes from using it.

  • 4. Optimal Allocation of Resources

  • It is challenging for the OS to handle resource allocation properly.

  • Issues of Concurrency

  • 1. Non-atomic

    Operations that are non-atomic but interruptible by several processes may happen issues. A non-atomic operation depends on other processes, and an atomic operation runs independently of other processes.

  • 2. Deadlock

    In concurrent computing, it occurs when one group member waits for another member, including itself, to send a message and release a lock. Software and hardware locks are commonly used to arbitrate shared resources and implement process synchronization in parallel computing, distributed systems, and multiprocessing.

  • 3. Blocking

  • A blocked process is waiting for some event, like the availability of a resource or completing an I/O operation. Processes may block waiting for resources, and a process may be blocked for a long time waiting for terminal input. If the process is needed to update some data periodically, it will be very undesirable.

  • 4. Race Conditions

  • A race problem occurs when the output of a software application is determined by the timing or sequencing of other uncontrollable events. Race situations can also happen in multithreaded software, runs in a distributed environment, or is interdependent on shared resources.

  • 5. Starvation

  • A problem in concurrent computing is where a process is continuously denied the resources it needs to complete its work. It could be caused by errors in scheduling or mutual exclusion algorithm, but resource leaks may also cause it.