Concurrency Terminology - a Simplified Glossary

Concurrency Terminology - a Simplified Glossary

This article aims at providing a pedagogical understanding of the different terms associated with multithreading and concurrency. The article uses terms from Java, but the underlying concepts remain the same across all platforms.

Resource

  • A Resource is anything that can be used to perform a task - CPU, memory, data, and so on.

  • However, in the context of Concurrency, the term Resource specifically refers to state or data. These can be:

    • Simple data like Integers and Strings.

    • More complex data like Arrays and Collections.

    • File and Connection Handles.

    • Message or Work Queues.

    • ....essentially any object that we create in a program is a resource.

Shareable Resources within a Process (that is, between the threads)

  • Since every process has a heap memory, resources created and stored on the Heap are shareable among its threads.

  • The following items are stored on the Heap in Java:

    1. Objects

    2. Member variables inside objects

    3. Static variables

  • While resources like CPU and memory outside a process are also shareable, the focus in multithreading is on what's stored on the heap.

Atomic Operations

  • Operations whose all steps must be executed or none at all, are called Atomic Operations.

  • This implies that nothing from outside an atomic operation can read, observe or access any of its intermediate states.

Critical Section

  • A Critical Section is that part of a program that must be executed "atomically" - either all steps in that part execute, or none.

  • Such parts of a program often have shared resources and have a logical entry point and a logical exit point.

  • For atomic execution to hold, a thread cannot enter a critical section if another thread has already entered it and not yet exited. This is because no one else must see the intermediate state(s) of an atomic operation.

Race Condition

  • A race condition occurs when the order of execution of multiple threads accessing a shared resource may lead to different outcomes.

  • Such conditions involve at least one thread modifying the shared resource.

  • The core issue lies in the execution of non-atomic operations on the shared resource.

  • These parts of the program, as previously introduced, are the critical sections that must be identified and executed atomically.

Synchronization

  • Synchronization is a mechanism to ensure that multiple threads interacting with a shared resource do so harmoniously to avoid chaos, that is, unexpected outcomes.

  • Essentially, synchronization ensures that a single thread is allowed to access or execute actions on the shared resource at any given time.

...it's a wrap...for now...

This list is not exhaustive, and I intend to add more interesting terms as I discover them. So, anticipate the list growing over time!

Thanks!

Did you find this article valuable?

Support Learning Backend by becoming a sponsor. Any amount is appreciated!