Logo

dev-resources.site

for different kinds of informations.

Swift Concurrency

Published at
7/9/2024
Categories
multithreading
threading
Author
vinaykumar0339
Categories
2 categories in total
multithreading
open
threading
open
Author
14 person written this
vinaykumar0339
open
Swift Concurrency

What is Concurrency?

In Real Life:

Concurrency in real life refers to the ability to handle multiple activities simultaneously within a given timeframe. This can be seen in various scenarios where multiple tasks are being managed simultaneously.

Examples:

  • Chef in a Kitchen: A chef might prepare several dishes simultaneously. While one dish is baking in the oven, the chef can chop vegetables for another dish. This is the concurrent execution of tasks.
  • Office Work: An employee might be handling emails, answering phone calls, and attending daily meetings. These tasks overlap in time, demonstrating concurrency.
  • Traffic Management: Traffic lights at an intersection manage the flow of cars from different directions. While cars move in one direction, others wait, and pedestrians might cross the street, all managed concurrently.

In Programming:

In programming, concurrency refers to the execution of multiple tasks or processes simultaneously, potentially overlapping in execution time. It is a way to structure a program to do multiple things at once, improving efficiency and performance.

Examples:

  • Multithreading: Running multiple threads within a single application. Each thread can perform a different task, such as fetching data from the network, processing user input, and updating the user interface.
  • Asynchronous Programming: Using constructs like async/await to perform non-blocking operations. For instance, fetching data from a server while allowing the user interface to remain responsive.
  • Parallel Processing: Executing multiple processes or computations simultaneously, often on different CPU cores. This is common in scientific computing, image processing, and machine learning tasks.

Concurrency

What is Parallelism?

In Real Life:

Parallelism in real life refers to the simultaneous execution of multiple tasks by multiple resources. It involves doing multiple things at the same time.

Examples:

  • Construction Site: Workers on a construction site performing different tasks simultaneously, such as one worker laying bricks while another installs windows.
  • Orchestra: Different musicians play their instruments at the same time to create a symphony.
  • Restaurant: Multiple chefs in a restaurant kitchen cooking different dishes at the same time, each using different equipment

Programming:

In programming, parallelism refers to the simultaneous execution of multiple computations or processes. It typically involves dividing a task into subtasks that can be processed concurrently on multiple processors or cores.

Examples:

  • Parallel Processing: Running multiple computations simultaneously on different CPU cores to speed up processing time.
  • Parallel Algorithms: Algorithms that divide a problem into subproblems that can be solved concurrently, like matrix multiplication or sorting algorithms.
  • Distributed Systems: Multiple servers processing different parts of a task at the same time to handle large-scale computations, such as in data centres or cloud computing Parallelism

Concurrency vs Parallelism?

Concurrency vs Parallelism

Concurrency: Two queues share one vending machine, serving one person at a time by alternating between queues.
Parallelism: Each queue has its vending machine, allowing both queues to be served simultaneously.

Parallelism Will give more speed but it involves more CPU resources.

Because Parallelism involves more resources we need to find a way that Concurrency can be achieved.

How Can We Achieve Concurrency in iOS?

  1. Achieving multi-threading by creating threads manually
  2. GCD (Grand Central Dispatch)
  3. Operation Queues
  4. Modern Concurrency By Swift. (async and await)
multithreading Article's
30 articles in total
Favicon
Python 3.13: The Gateway to High-Performance Multithreading Without GIL
Favicon
# Boost Your Python Tasks with `ThreadPoolExecutor`
Favicon
ReentrantReadWriteLock
Favicon
ReentrantLock in Java
Favicon
Synchronizing Threads with Semaphores: Practicing Concurrency in Java - LeetCode Problem 1115, "Print FooBar Alternately"
Favicon
Effective Ways to Use Locks in Kotlin
Favicon
Python Multithreading and Multiprocessing
Favicon
Introducing Robogator for PS and C#
Favicon
Multithreading Concepts Part 3 : Deadlock
Favicon
Multithreading Concepts Part 2 : Starvation
Favicon
Parallelism, Asynchronization, Multi-threading, & Multi-processing
Favicon
Using WebSocket with Python
Favicon
Power of Java Virtual Threads: A Deep Dive into Scalable Concurrency
Favicon
GIL "removal" for Python true multi threading
Favicon
Optimizing Your Development Machine: How Many Cores and Threads Do You Need for Programming?
Favicon
Multithreading Concepts Part 1: Atomicity and Immutability
Favicon
The Benefits of Having More Threads than Cores: Unlocking the Power of Multi-threading in Modern Computing
Favicon
Mastering Java Collections with Multithreading: Best Practices and Practical Examples
Favicon
Understanding Multithreading: Inner Workings and Key Concepts
Favicon
Handling Concurrency in C#: A Guide to Multithreading and Parallelism
Favicon
MultiThreading vs MultiProcessing
Favicon
Achieving multi-threading by creating threads manually in Swift
Favicon
Multithreading in Java : A Deep Dive
Favicon
Understanding std::unique_lock and std::shared_lock in C++
Favicon
Swift Concurrency
Favicon
Mastering Multithreading in C Programming: A Deep Dive with In-Depth Explanations and Advanced Concepts
Favicon
Understanding Multithreading in Python
Favicon
Introduction to Monitor Class in C#
Favicon
Deep Dive Into Race Condition Problem inΒ .NET
Favicon
Goroutines: Solving the problem of efficient multithreading

Featured ones: