<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Lomas Singh</title>
    <description>The latest articles on Forem by Lomas Singh (@lomas).</description>
    <link>https://forem.com/lomas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F443754%2F0f819aba-12e7-4bcc-8e6a-adc37f43a493.png</url>
      <title>Forem: Lomas Singh</title>
      <link>https://forem.com/lomas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lomas"/>
    <language>en</language>
    <item>
      <title>What is multithreading?</title>
      <dc:creator>Lomas Singh</dc:creator>
      <pubDate>Sat, 25 Sep 2021 18:30:12 +0000</pubDate>
      <link>https://forem.com/lomas/what-is-multithreading-37jg</link>
      <guid>https://forem.com/lomas/what-is-multithreading-37jg</guid>
      <description>&lt;h3&gt;
  
  
  What is multithreading?
&lt;/h3&gt;

&lt;p&gt;Multithreading is a CPU feature which allows creation and execution of multiple threads within a process concurrently or parallelly or both.&lt;/p&gt;

&lt;p&gt;During development, the programmer divides the processes into threads i.e. &lt;strong&gt;separate units of semi-independent instructions extracted from the process.&lt;/strong&gt; These threads are managed by the application.&lt;/p&gt;

&lt;p&gt;With multithreading more than one user &lt;em&gt;(here user can also be another program)&lt;/em&gt; can use a program at a time or even multiple requests by the same user can be managed by the program without having to run multiple copies of it in the computer.&lt;/p&gt;

&lt;p&gt;Each user request for a program or system service is kept track of as &lt;em&gt;a thread with a separate identity.&lt;/em&gt; There are some unique data incorporated in each thread that helps to identify them, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Program counter:&lt;/strong&gt; A program counter is responsible for keeping track of instructions and to tell which instruction to execute next.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Register:&lt;/strong&gt; System registers are there to keep track of the current working variable of a thread.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stack:&lt;/strong&gt; It contains the history of thread execution.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As programs work on behalf of the initial request for that thread and are interrupted by other requests, the status of work on behalf of that thread is kept track of until the work is completed.&lt;/p&gt;

&lt;p&gt;In multithreading, threads share the resources of a single or multi-cores.&lt;br&gt;
Depending on the hardware, threads can run fully parallel if they are distributed to their own CPU core.&lt;/p&gt;

&lt;p&gt;The execution in this is both concurrent and parallel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Concurrent Execution:&lt;/strong&gt; If the processor can switch execution resources between threads in a multithreaded process on a single processor, it is a concurrent execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Parallel Execution:&lt;/strong&gt; When each thread in the process can run on a separate processor at the same time in the same multithreaded process, then it is said to be a parallel execution.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples of threads are several background/front end tasks such as updating data in the file system, capturing the log files, multiple windows operations management, file scanning, continuous interaction with users.&lt;/p&gt;

&lt;h3&gt;
  
  
  • Advantages of multithreading:
&lt;/h3&gt;

&lt;p&gt;The main reason for incorporating threads into an application is to improve its performance.&lt;br&gt;
It is usually used for its essential characteristics like it uses the system resources efficiently, high performance, greatly responsive, and also its parallel execution ability.&lt;/p&gt;

&lt;p&gt;Threading can be useful in a single-processor system because it allows the primary execution thread to be responsive to user input while supporting threads execute long-running tasks in the background that do not require user intervention.&lt;/p&gt;

&lt;p&gt;Application responsiveness is improved as requests from one thread do not block requests from other threads.&lt;/p&gt;

&lt;p&gt;Additionally, multithreading is less resource-intensive than running multiple processes at the same time. There is much more overhead, time consumption, and management involved in creating processes as compared to creating and managing threads.&lt;/p&gt;

&lt;p&gt;Regards,&lt;br&gt;
Lomas Singh&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Image credits&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/vectors/people"&gt;Cover image by freepik - &lt;/a&gt;&lt;a href="http://www.freepik.com"&gt;www.freepik.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>multithreading</category>
      <category>operatingsystem</category>
      <category>performance</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Processes and Threads</title>
      <dc:creator>Lomas Singh</dc:creator>
      <pubDate>Tue, 21 Sep 2021 08:11:31 +0000</pubDate>
      <link>https://forem.com/lomas/processes-and-threads-189j</link>
      <guid>https://forem.com/lomas/processes-and-threads-189j</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part 2 of “Getting started with multithreading” series. Click &lt;a href="https://dev.to/lomas/synchronous-asynchronous-concurrency-and-parallelism-3h5i"&gt;here&lt;/a&gt; for part 1.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  1) What are processes?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632210296518%2FlBbOOqm5J.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632210296518%2FlBbOOqm5J.jpeg" alt="one to many.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A process initializes a program. Programs are nothing but a passive collection of instructions stored in a file on a disk or simply our software.&lt;/p&gt;

&lt;p&gt;A Process contains the program’s code and its activity. It’s the self-contained unit of execution that has all the things necessary to accomplish the mission.&lt;/p&gt;

&lt;p&gt;A program doesn’t consume any memory; it is a passive entity whereas a process consumes some memory (RAM) and gets CPU time. It’s an instance of a program running on a computer.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;&lt;em&gt;“program becomes a process"&lt;/em&gt;&lt;/strong&gt; when loaded into memory (RAM) and thus is an active entity or a dynamic entity. &lt;/p&gt;

&lt;p&gt;A program can have several processes; for example, opening several instances of the same program often results in more than one process being executed. Every process has its own memory space or address space.&lt;/p&gt;

&lt;p&gt;To visualize in simple terms, consider a program as the McDonald company and its restaurants as the processes. The company has a set of rules and regulations for the operation of restaurants and recipes of the food, but the actual implementation of those rules and recipes is run by the restaurant.&lt;br&gt;
And Threads(see below) are the workers in a particular restaurant.&lt;/p&gt;

&lt;h3&gt;
  
  
  2) What are threads?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632210612730%2FarKE_BUU3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632210612730%2FarKE_BUU3.jpeg" alt="thread-roll-close-up.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A thread is a &lt;strong&gt;&lt;em&gt;portion of the process&lt;/em&gt;&lt;/strong&gt;. Thread is short for the &lt;strong&gt;thread of execution&lt;/strong&gt;. It is a series of commands (a block of code) that exists as a unit of work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A process may have several threads.&lt;/em&gt;&lt;/strong&gt; Each of these threads executes semi-independently while sharing common information. They can run concurrently or in parallel inside the same process.&lt;/p&gt;

&lt;p&gt;Each thread has its executor, and this executor can perform only one thread at a time.&lt;/p&gt;

&lt;p&gt;Threads run in a shared memory space inside its process. If there is no need of sharing the shared resources then tasks can run concurrently inside the same thread, there is no need to run them in different threads. It is cheaper in terms of resources to arrange concurrent execution with time-slicing inside one thread.&lt;/p&gt;

&lt;p&gt;A thread is also known as a &lt;strong&gt;lightweight process&lt;/strong&gt; because of the system resources they consume, as compared with processes.&lt;/p&gt;

&lt;p&gt;I found a very easy to understand analogy for threads on &lt;a href="https://stackoverflow.com/a/5201906/14022489" rel="noopener noreferrer"&gt;StackOverflow&lt;/a&gt; as follows:&lt;br&gt;
Suppose you’re reading a book, and you want to take a break right now, but you want to be able to come back and resume reading from the exact point where you left off.&lt;br&gt;
One way to achieve that is by jotting down the page number, line number, and word number. So your execution context for reading a book is these 3 numbers.&lt;br&gt;
If you have a roommate and she’s using the same technique, she can take the book while you’re not using it, and resume reading from where she stopped. Then you can take it back, and resume it from where you were.&lt;/p&gt;

&lt;p&gt;Threads work in the same way. &lt;strong&gt;&lt;em&gt;Just like you can share a book with your friend, many tasks can share a CPU.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In technical terms, an &lt;strong&gt;execution context&lt;/strong&gt; (therefore a thread) consists of the independent &lt;strong&gt;set of values for the processor registers&lt;/strong&gt;(for single-core).&lt;/p&gt;

&lt;p&gt;The resources associated with a process include memory pages (all the threads in a process have the same view of memory), file descriptors (e.g., open sockets), and security credentials (e.g., the ID of the user who started the process.&lt;/p&gt;

&lt;h3&gt;
  
  
  • What is time slicing?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632210905499%2FCX1CqRon4.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632210905499%2FCX1CqRon4.jpeg" alt="toy-bricks-table-with-word-time.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A CPU is giving you the illusion that it’s doing multiple computations at the same time. It does that by spending a bit of time on each computation. It can do that because it has an execution context for each computation(Read above to understand “execution context”).&lt;/p&gt;

&lt;p&gt;The operating system can manage multiple threads and assign a thread a piece &lt;strong&gt;&lt;em&gt;(“slice”)&lt;/em&gt;&lt;/strong&gt; of processor time before switching to another thread to give it a turn to do some work. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;At its core, a processor can simply execute a command, it has no concept of doing two things at one time. The operating system simulates this by allocating slices of time to different threads.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, if you introduce multiple cores/processors into the mix, then things can actually happen at the same time. The operating system can allocate time to one thread on the first processor, then allocate the same block of time to another thread on a different processor. All of this is about allowing the operating system to manage the completion of your task while you can go on in your code and do other things.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;“execution inside the threads”&lt;/strong&gt; can be synchronous or asynchronous but never parallel because of the “single executor per thread”.&lt;/p&gt;

&lt;h3&gt;
  
  
  • Process Vs Threads:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632168116533%2FbqyUcL59i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1632168116533%2FbqyUcL59i.png" alt="wepik-2021821-12443.png"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Each process has its own memory space whereas,&lt;br&gt;
Threads use the memory of the process they belong to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Communication between different processes is slow since processes have different memory addresses whereas,&lt;br&gt;
Communications between threads are faster due to sharing of the same memory with the process they belong to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Processes are independent of one another due to separate memory spaces whereas,&lt;br&gt;
Threads run in shared memory space.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While one process is blocked, no other process can be executed until the first process is unblocked whereas,&lt;br&gt;
If one thread is blocked and waiting, a second thread in the same task can run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Every process has at least one thread&lt;/em&gt;&lt;/strong&gt; as they do all the work. There is no such thing as a thread without a process or a process without a thread. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each process starts with a thread called the &lt;strong&gt;main thread.&lt;/strong&gt; It can initiate the creation of additional threads inside the application, and every newly created thread can do it as well.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Process management is the responsibility of the operating system whereas,&lt;br&gt;
Thread management is the concern of the application.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Regards,&lt;br&gt;
Lomas Singh&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Image credits:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cover photo by 8photo&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/photos/business" rel="noopener noreferrer"&gt;Process image by onlyyouqj - &lt;/a&gt;&lt;a href="http://www.freepik.com" rel="noopener noreferrer"&gt;www.freepik.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/photos/background" rel="noopener noreferrer"&gt;Threads image by rawpixel.com - &lt;/a&gt;&lt;a href="http://www.freepik.com" rel="noopener noreferrer"&gt;www.freepik.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/photos/time" rel="noopener noreferrer"&gt;Time-slicing image by Racool_studio - &lt;/a&gt;&lt;a href="http://www.freepik.com" rel="noopener noreferrer"&gt;www.freepik.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/photos/business" rel="noopener noreferrer"&gt;Process vs threads image by jcomp - &lt;/a&gt;&lt;a href="http://www.freepik.com" rel="noopener noreferrer"&gt;www.freepik.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>threads</category>
      <category>multithreading</category>
      <category>programming</category>
      <category>performance</category>
    </item>
    <item>
      <title>Synchronous, Asynchronous, Concurrency and Parallelism</title>
      <dc:creator>Lomas Singh</dc:creator>
      <pubDate>Sun, 12 Sep 2021 11:44:35 +0000</pubDate>
      <link>https://forem.com/lomas/synchronous-asynchronous-concurrency-and-parallelism-3h5i</link>
      <guid>https://forem.com/lomas/synchronous-asynchronous-concurrency-and-parallelism-3h5i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is part 1 of “Getting started with multithreading” series.&lt;br&gt;
Before getting to multithreading let’s first prepare ourselves with some prerequisites i.e. &lt;strong&gt;Synchronous and Asynchronous programming, Concurrency and Parallelism.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  1) What is Synchronous programming?
&lt;/h4&gt;

&lt;p&gt;It is a programming workflow in which operations take place one by one.&lt;/p&gt;

&lt;p&gt;The program moves to the next step when the current step has completed execution and has returned an outcome.&lt;br&gt;
It has one executor only.&lt;/p&gt;

&lt;p&gt;Most of the activities should go synchronously if their goal is to achieve some specific results.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Input -&amp;gt; processing -&amp;gt; output -&amp;gt; input -&amp;gt; processing -&amp;gt; output....&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;OR,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Task 1 -&amp;gt; Task 2 -&amp;gt; ……… Task n&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;E.g.- Words in a sentence, making a cup of tea, car assembling, etc&lt;/p&gt;

&lt;h4&gt;
  
  
  2) What is Asynchronous programming?
&lt;/h4&gt;

&lt;p&gt;It is a programming workflow in which you can move to another operation before the previous one finishes.&lt;/p&gt;

&lt;p&gt;Operations of this kind often emerge when there is a need for waiting. You begin a routine, and let it run in the background while you start your next, then at some point, say “wait for this to finish”.&lt;/p&gt;

&lt;p&gt;It’s more like:&lt;br&gt;
Start &lt;code&gt;A -&amp;gt; B -&amp;gt; C -&amp;gt; D -&amp;gt;....&lt;/code&gt; Wait for &lt;code&gt;A&lt;/code&gt; to finish.&lt;/p&gt;

&lt;p&gt;The advantage is that you can execute &lt;code&gt;B&lt;/code&gt;,&lt;code&gt;C&lt;/code&gt; and or &lt;code&gt;D&lt;/code&gt; while &lt;code&gt;A&lt;/code&gt; is still running in the background or on a separate thread (which we will get to know a bit later), so you can take better advantage of your resources and have fewer “hangs” or “waits”.&lt;/p&gt;

&lt;p&gt;E.g.- You are eating your food on an aircraft while flying, or you are recording video while bungee jumping etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  3) What is Concurrency?
&lt;/h4&gt;

&lt;p&gt;It is an ability to execute multiple operations at the same time and no predefined order without affecting the final outcome.&lt;/p&gt;

&lt;p&gt;Concurrency appears when there is a scarce shared resource, and workers compete for access to it.&lt;br&gt;
The process of managing access to scarce shared resources for concurrent tasks is called Synchronization.&lt;/p&gt;

&lt;p&gt;Concurrency can appear with one executor and with multiple.&lt;/p&gt;

&lt;p&gt;For concurrency, it’s necessary to have:&lt;br&gt;
more than one task in operation&lt;br&gt;
at least one critical section (scarce shared resource required for task execution) for these tasks.&lt;/p&gt;

&lt;p&gt;The second name of concurrency is multitasking because there is no such thing as concurrency for one task.&lt;/p&gt;

&lt;h4&gt;
  
  
  4) What is Parallelism?
&lt;/h4&gt;

&lt;p&gt;Parallel processing is a method of simultaneously breaking up and running operations via multiple executors, thereby reducing processing time. These can be either several independent operations or one big task split into smaller subtasks and divided between workers.&lt;/p&gt;

&lt;p&gt;Each task in parallel processing is running in a continuous period as a whole unit process.&lt;/p&gt;

&lt;p&gt;The parallel execution is possible only if there is more than one executor.&lt;br&gt;
Since there are many executors processing tasks in parallel, the second name of parallelism is multiprocessing.&lt;/p&gt;

&lt;h4&gt;
  
  
  • What is the difference between concurrency and parallelism?
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq4v51t55jvfffjyme0p.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq4v51t55jvfffjyme0p.jpeg" alt="Difference" width="800" height="707"&gt;&lt;/a&gt;&lt;br&gt;
Parallelism is, in some sense, a concurrency without a limited resource for task execution. If shared resources are sufficient for all participants, processes can run in parallel. They don’t need to compete for resources and get access to it by turn because we distribute tasks among several executors so that everyone has only one.&lt;/p&gt;

&lt;p&gt;In concurrency two or more operations can start, run and complete in overlapping time periods. It doesn’t necessarily mean they’ll ever be running at the same instant, e.g.- multitasking on a single-core machine.&lt;br&gt;&lt;br&gt;
But, Parallelism is when tasks literally run at the same time, e.g.- on a multicore processor.&lt;/p&gt;

&lt;p&gt;Concurrency is a property of a program or system whereas Parallelism is the run-time behavior of executing multiple operations at the same time.&lt;/p&gt;

&lt;p&gt;To visualize in simple terms:&lt;br&gt;
Concurrency is like having a juggler juggle many balls. Regardless of how it seems, the juggler is only catching/throwing one ball per hand at a time.&lt;br&gt;
Parallelism is having multiple jugglers juggle balls simultaneously.&lt;/p&gt;

&lt;p&gt;Use the term “parallel” when the simultaneous execution is assured or expected, and use the term “concurrent” when it is uncertain or irrelevant if simultaneous execution will be employed.&lt;/p&gt;

&lt;h4&gt;
  
  
  • Can we mix concurrency and parallelism together?
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5biLGizD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1631435113531/PrFbL5tte.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5biLGizD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1631435113531/PrFbL5tte.jpeg" alt="GettyImages-594836477-58fe53963df78ca159068b1a.jpg" width="768" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Concurrency and parallelism often intersect and appear together. They can mutate one to another.&lt;/p&gt;

&lt;p&gt;Concurrency is dealing with lots of things at once whereas parallelism is about doing lots of things at once.&lt;/p&gt;

&lt;p&gt;Concurrency can appear with one executor or with multiple whereas Parallelism appears only when there are multiple executors. Parallel tasks can become concurrent and so on.&lt;br&gt;
Practically, all combinations of concurrency and parallelism are possible.&lt;/p&gt;

&lt;p&gt;For example, you can drink a glass of water while giving a speech.&lt;br&gt;
Here you can drink and speak simultaneously in several combinations. You can drink a whole glass of water and then complete your speech, or you can drink half of the water in the glass and then complete half of the speech, then repeat again, etc.&lt;br&gt;&lt;br&gt;
In parallelism, you deliver your speech in a team of two. You can drink water while letting your friend deliver the speech. This time, the two tasks are really executed simultaneously, and it’s called parallel.&lt;/p&gt;

&lt;p&gt;Parallelism is a specific kind of concurrency where tasks are really executed simultaneously.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Link to my original post : &lt;a href="https://iamlomas.medium.com/synchronous-asynchronous-concurrency-and-parallelism-9eb8336df120"&gt;https://iamlomas.medium.com/synchronous-asynchronous-concurrency-and-parallelism-9eb8336df120&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Regards, &lt;br&gt;
Lomas Singh&lt;/p&gt;

</description>
      <category>programming</category>
      <category>performance</category>
      <category>parallelism</category>
      <category>concurrency</category>
    </item>
  </channel>
</rss>
