<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Preet Padariya on Medium]]></title>
        <description><![CDATA[Stories by Preet Padariya on Medium]]></description>
        <link>https://medium.com/@preetpadariya?source=rss-9cdab6f882b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3eKNb-oHRWpHmWvg7gcmgw.jpeg</url>
            <title>Stories by Preet Padariya on Medium</title>
            <link>https://medium.com/@preetpadariya?source=rss-9cdab6f882b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 18:50:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@preetpadariya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NAT(Network Address Translation) Part2 without using AWS]]></title>
            <link>https://preetpadariya.medium.com/nat-network-address-translation-part2-without-using-aws-c61fa9c194ed?source=rss-9cdab6f882b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c61fa9c194ed</guid>
            <category><![CDATA[internet-gateway]]></category>
            <category><![CDATA[nat-gateway]]></category>
            <dc:creator><![CDATA[Preet Padariya]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 19:02:07 GMT</pubDate>
            <atom:updated>2023-03-22T19:04:51.579Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is NAT?</h3><p>NAT is Network Address Translation. Basically, It is a technique in which a router or a similar device translates one IP address into another IP address information in packets’ IP headers as they transit across a traffic routing device.</p><p>A router translates the private address of an internal host into a public IP address for outgoing traffic with that from the opposite side similarly router will translate its own public IP address into a private one for the incoming traffic. This lets organizations use one public IP address and many private IP addresses within the network.</p><p>An example of a real-life situation is a receptionist at a company. Just call on the company and once you reach the receptionist, he/she will transfer your call to one of the private numbers inside the company.</p><h3>What is the need for NAT?</h3><p>As we cannot use private IPv4 addresses to access the internet at the same time, the number of public IPv4 addresses is limited. Therefore, we need a way in which hosts in our network that have been assigned private IPv4 addresses can access the internet. So here is the need for Network Address Translation (NAT) as few public IPv4 addresses are made which are used to access the internet even if they have many hosts who have been assigned private IPv4 addresses.</p><h3>DEMO/Confirmation</h3><blockquote>Step 1: Install the Required Packages</blockquote><p>To configure the NAT server, we need to install the iptable packages. Running the below command in cmd the package will be installed:</p><p>```sudo apt-get install iptables```</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*wTrOf0Dhp7E4c7kHdPn1Nw.png" /><figcaption>install of iptables</figcaption></figure><blockquote>Step 2: Enable IP Forwarding</blockquote><p>First, we need to enable the IP forwarding in Ubuntu because by default it is disabled. You can do this by editing the `/etc/sysctl.conf` file. Open the file with a text editor such as nano:</p><p>```nano /etc/sysctl.conf```</p><p>Uncomment the following line by removing the “#” sign to enable IP forwarding:</p><p>```net.ipv4.ip_forward=1```</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*xQCBflecyAN6ElEHUAweGw.png" /><figcaption>enable IP forwarding</figcaption></figure><p>Save the file and run the following command:</p><p>```sysctl -p```</p><p>This command will reload the modified configuration file.</p><blockquote>Step 3: Configure IPTables</blockquote><p>Next, we need to configure IPTables, which is the Linux firewall. You can do this by running the following commands:</p><p>``` iptables -F</p><p>iptables -t nat -F</p><p>iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE</p><p>iptables -A FORWARD -i eth1 -j ACCEPT```</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*r-pvGAs_2Tz-n5lbyAe6OQ.png" /><figcaption>configure IPTables</figcaption></figure><p>The first two commands remove any previous rules from the IPTables configuration. The third command adds a Masquerade rule to the POSTROUTING chain of the NAT table, which allows the device to share its internet connection with other devices. Replace `eth0` with the device’s name connected to the internet.</p><p>The last command adds a rule to the FORWARD chain of the IPTables configuration, which allows the forwarding of packets from the local network to the internet. Replace `eth1` with the device’s name connected to the local network.</p><blockquote>Step 4: Save IPTables Configuration</blockquote><p>After configuring IPTables, you need to save the configuration for it to persist across reboots. You can do this by running the following command:</p><p>```sh -c “iptables-save &gt; /etc/iptables.rules”```</p><p>This command will save the IPTables configuration to the `/etc/iptables.rules` file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*TU3YZB5tJ2yqiNK0IOo95g.png" /></figure><p>These lines tell Ubuntu to load the IPTables configuration from `/etc/iptables.rules` during boot, and to save the configuration to the same file during the shutdown.</p><p>Save the file and reboot the device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*0SV84Nb6JQJslV0Ohq2KaA.png" /><figcaption>File</figcaption></figure><blockquote><em>Conclusion</em></blockquote><p>From this google.com server identify this private instance through the NAT gateway IP. With that global address space allocation in face of IPv4 address exhaustion by sharing one Internet-routable IP address of a NAT gateway for an entire private network. Taking the CHARUSAT example the PCs of the lab are in a private subnet and the wi-fi access/routers are using a NAT gateway.</p><blockquote><em>Contributed by</em></blockquote><p>Jay Nakarani(20CE058) &amp; Preet Padariya(20CE063)</p><blockquote><em>NAT using AWS</em></blockquote><p><a href="https://preetpadariya.medium.com/nat-network-address-translation-using-aws-part1-3e9d0a65f2bf">NAT using AWS</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c61fa9c194ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NAT (Network Address Translation) using AWS Part1]]></title>
            <link>https://preetpadariya.medium.com/nat-network-address-translation-using-aws-part1-3e9d0a65f2bf?source=rss-9cdab6f882b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e9d0a65f2bf</guid>
            <category><![CDATA[aws-nat-gateway]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[nat]]></category>
            <category><![CDATA[aws-internet-gateway]]></category>
            <dc:creator><![CDATA[Preet Padariya]]></dc:creator>
            <pubDate>Wed, 22 Mar 2023 18:58:43 GMT</pubDate>
            <atom:updated>2023-03-22T19:03:20.985Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What is NAT?</strong></h3><p>NAT is Network Address Translation. Basically, It is a technique in which a router or a similar device translates one IP address into another IP address information in packets’ IP headers as they transit across a traffic routing device.</p><p>A router translates the private address of an internal host into a public IP address for outgoing traffic with that from the opposite side similarly router will translate its own public IP address into a private one for the incoming traffic. This lets organizations use one public IP address and many private IP addresses within the network.</p><p>An example of a real-life situation is a receptionist at a company. Just call on the company and once you reach the receptionist, he/she will transfer your call to one of the private numbers inside the company.</p><h3><strong>What is the need for NAT?</strong></h3><p>As we cannot use private IPv4 addresses to access the internet at the same time, the number of public IPv4 addresses is limited. Therefore, we need a way in which hosts in our network that have been assigned private IPv4 addresses can access the internet. So here is the need for Network Address Translation (NAT) as few public IPv4 addresses are made which are used to access the internet even if they have many hosts who have been assigned private IPv4 addresses.</p><h3><strong>What is AWS?</strong></h3><p>AWS is Amazon Web Services which evolving cloud computing platform provided by Amazon. AWS services can offer well-organized tools such as compute power, database storage, content delivery services, and many more services.</p><h3><strong>Amazon Services used in this blog</strong></h3><blockquote><strong>EC2 instances:</strong></blockquote><p>Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage. In this, we are using an EC2 instance with the OS of Amazon Linux.</p><blockquote><strong>VPC:</strong></blockquote><p>Amazon Virtual Private Cloud (Amazon VPC) enables you to launch AWS resources into a virtual network that you’ve defined. VPC is a virtual network that closely resembles a traditional network that you would operate in your own data center. After you create a VPC, you can add subnets.</p><blockquote><strong>Internet Gateway:</strong></blockquote><p>It allows communication between your VPC and the internet. It supports IPv4 and IPv6 traffic. An internet gateway enables resources in your public subnets (such as EC2 instances) to connect to the internet if the resource has a public IPv4 address or an IPv6 address.</p><blockquote><strong>NAT Gateway:</strong></blockquote><p>A NAT gateway is a Network Address Translation (NAT) service. You can use a NAT gateway so that instances in a private subnet can connect to services outside your VPC but external services cannot initiate a connection with those instances.</p><h3>DEMO/Confirmation</h3><p>Given below diagram is an overview of the Network which we are going to make…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*CsSFc025Nac4R1oK0eiOZA.png" /><figcaption>Network overview(reference AWS)</figcaption></figure><blockquote>Step: 1</blockquote><p>Create two EC2 instances that use Amazon Linux as OS and name them “public” and “private”. While making the instances put the “public” instance into the public subnet (10.200.0.16) in that must choose the public subnet and the “private” instance into the private subnet (10.200.1.98) in that must choose the private subnet.</p><blockquote>Step: 2</blockquote><p>Connect to “public” EC2 instance. Now ping google.com (to check the connectivity) this will ping successfully, so we have proved that we are connected to an internet gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*LO6iTNWd0QMStyVwb4Txfw.png" /><figcaption>ping of google.com</figcaption></figure><blockquote>Step: 3</blockquote><p>To check that private and public instances are connected to each other, we will ping the private instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*dGUAfhD0utSbrJLZ_W1tLw.png" /><figcaption>ping to “private” EC2 instance</figcaption></figure><blockquote>Step: 4</blockquote><p>Now we are going to “private” EC2 instance through “public” EC2 instance through</p><p>“ssh -i &lt;&lt;passwordFilePath&gt;&gt; <a href="/service/mailto:ec2-user@10.200.1.98">ec2-user@10.200.1.98</a>”</p><p>So, from this, we are on the CLI of “private”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*pky7nb-PTG80P4ysIVByBQ.png" /><figcaption>From “public” instance to “private” instance</figcaption></figure><blockquote>Step: 5</blockquote><p>From that ping to google.com (to check the connectivity) this will not ping, so we have proved that we are not connected to an internet gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*3P2j1s8rTY_JXoCrrImd2g.png" /><figcaption>ping to google.com</figcaption></figure><blockquote>Step: 6</blockquote><p>Now ping to our “public” EC2 instance. This will ping to the public instance successfully, so we can say “private” is connected to the public instance but not connected to an internet gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*OYEigKZNgDOwiW8sc4-_7A.png" /><figcaption>ping to “public” instance</figcaption></figure><blockquote>Step: 7</blockquote><p>Now we going to connect the private instance with the NAT gateway. Now to check we will ping google.com (to check the connectivity) this will ping successfully, so we have proved that we are connected to the NAT gateway and we can access the internet Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*zvGdQ2IU1ghA2zoJGKe11A.png" /><figcaption>ping to google.com</figcaption></figure><blockquote>Conclusion</blockquote><p>From this google.com server identify this private instance through the NAT gateway IP. With that global address space allocation in face of IPv4 address exhaustion by sharing one Internet-routable IP address of a NAT gateway for an entire private network. Taking the CHARUSAT example the PCs of the lab are in a private subnet and the wi-fi access/routers are using a NAT gateway.</p><blockquote>Contributed by</blockquote><p>Jay Nakarani &amp; Preet Padariya</p><blockquote>References</blockquote><p>AWS</p><blockquote>NAT without AWS</blockquote><p><a href="https://preetpadariya.medium.com/nat-network-address-translation-part2-without-using-aws-c61fa9c194ed">NAT without AWS</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e9d0a65f2bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with “thread” in Python(Part-2)]]></title>
            <link>https://preetpadariya.medium.com/getting-started-with-thread-in-python-part-2-99d0c904aa32?source=rss-9cdab6f882b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/99d0c904aa32</guid>
            <dc:creator><![CDATA[Preet Padariya]]></dc:creator>
            <pubDate>Tue, 12 Apr 2022 08:15:52 GMT</pubDate>
            <atom:updated>2022-04-12T08:15:52.343Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Introduction</strong></blockquote><p>As we have discussed in part-I, that what is thread and why we need thread? As you might be aware that threading is a term which usually needed to achieve multi-tasking. In this part-II we will be giving you some glimpse of threading implementation in python. With the basic thread terminologies that we have covered in part-I will help you to understand better in this part so, let us start first look at “Threading” module in python.</p><blockquote><strong>Threading module in python</strong></blockquote><p>This threading module was included in python 2.4 which has provided much more powerful and high-level support for threads than the previous once.</p><p>In addition to some advance methods, this threading module consist “thread” class that implements threading and the methods; which are provided by the “thread” class are mentioned below.</p><p>1. run()</p><p>2. join([time])</p><p>3. start()</p><p>4. getName()</p><p>5. setName()</p><p>6. isAlive()</p><blockquote><strong>Creating a thread in python</strong></blockquote><p>So, let’s take a look that actually, how we can create the thread in python?</p><p>There are basically two ways to do so; first is by using Thread class and second is by using Thread class object. Both are mentioned briefly below.</p><blockquote><strong>By inheriting thread class</strong></blockquote><p>So here, we <strong>imported thread class</strong> from <strong>Threading module</strong>. After that, In Test class we have inherited in Thread class and <strong>overridden the run method</strong>. In run method we are calling “<strong>getName</strong>” method which returns the name of current thread which is executing.</p><blockquote><a href="https://gist.github.com/Harshil2312/19ca7112d8ced50fd4a652cd0b15a271">CODE</a></blockquote><p>After defining class, we created two objects of Test class. Now, if <strong>we want to start thread</strong> then we <strong>have to call start method</strong>. If we directly call the run() method then it will not create a Thread. After invoking start() method in this program we have total three threads. One is main thread second is t1 objects thread and last is t2 objects thread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*470MJ4ofdIYzyBHsmvkTLg.png" /><figcaption>OUTPUT</figcaption></figure><blockquote><strong>What is main thread?</strong></blockquote><p>In normal condition, the main thread is the thread <strong>from which</strong> <strong>the python interpreter was started</strong>. It is a basic and compulsory unit of execution for any program because without thread there is no existence of process. You can also consider that it is a by default thread, which will run without any invocation for execution of any python file.</p><p>You can also consider as <strong>abstract thread</strong> from which any number of <strong>child threads can be spawned</strong>, as we are doing.</p><blockquote><strong>By Using Thread class object</strong></blockquote><p>If we don’t want to create our own class then we can directly create thread class object and use it. At the time of creating object of thread class, we can give name of the thread and also target method name which will be called when we start the thread. If we don’t want to give name and other parameters then it’s also fine.</p><p>Here we have defined a two methods method1() and method2() and in that we are printing the name of the thread from where it is called.</p><p>After that we created t1 and t2 object with name Thread_1 and Thread_2 respectively. And also passing target parameter for t1 and t2 that is method1 and method2. Here, <strong>target</strong> parameter means when we called start() method then it is internally called our passing method.</p><p>And in Third object we didn’t give any parameter.</p><blockquote><a href="https://gist.github.com/Harshil2312/9aaa51a5f409a2aa035209583521fdd1">CODE</a></blockquote><p>The output look like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*6VjfwYsEZcwje14l9qIh_A.png" /><figcaption>OUTPUT</figcaption></figure><p>You might be wondering that what are these methods; which is used in here. Such as, start(), run(), etc. So, for that let’s take a look at those such methods.</p><blockquote><strong>Useful methods in thread class</strong></blockquote><p>There are several kinds of methos are there in thread class. Let’s talk about each methods, which are there exist in thread class.</p><blockquote>Run method</blockquote><p>The run method is inbuilt empty method of Thread class. The run() method defines the body of the thread. The run method gets it code the following two way.</p><p>1. when the run method is overridden in a subclass, as we have done in first example.</p><p>2. Second is using Thread class constructor. When Thread class object created a callable object is passed as a target through the constructor. As we have done in second example.</p><blockquote>Start method</blockquote><p>The start method is an inbuilt method of Thread class. Which is used to start a Thread. The start method calls run method internally.</p><p>This method must be called at most one time for one thread. If it called more than once it will give Runtime error. The return type of start method is none.</p><blockquote>Join method</blockquote><p>When join method is invoked, the calling thread is blocked till the thread object on which it was called is terminated.</p><p>For example, if join method is called from a main thread, the main thread waits till the child thread on which join invoked exits. The use of join method is, if join method is not invoked then the main thread may exit before the child thread, which will result undetermined behavior of programs and affect program invariants and integrity of the data on which the program operates.</p><blockquote><strong>Python code</strong></blockquote><blockquote><a href="https://github.com/Harshil2312/Pythonpracticales/blob/main/odd_even.py">CODE</a></blockquote><p>Here, this program creates two threads one is odd_thread and second is even_thread. odd_thread makes lists of odd numbers and even_threads make lists of even threads. Also, there is two functions print_odd() and print_even() which makes list of odd and even numbers and prints it.</p><p>The output look like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*R9nN5tM94qw4gwN_kShJTA.png" /><figcaption>OUTPUT</figcaption></figure><blockquote><strong>Python multithreading Applications</strong></blockquote><p>Most of the application you use in daily life have multiple threads running behind the scenes. Consider your internet browser. It is best example of multithreading programming. At any time, you may have number of tabs open, each one displaying various types of websites, video, blog, etc.</p><p>Another best example is Microsoft-word, Games, etc.</p><blockquote><strong>References</strong></blockquote><p><a href="https://www.iitk.ac.in/esc101/05Aug/tutorial/essential/threads/definition.html">· What Is a Thread?</a></p><p>· <a href="https://www.geeksforgeeks.org/thread-in-operating-system/">Thread in Operating System — GeeksforGeeks</a></p><p>· <a href="https://realpython.com/intro-to-python-threading/#conclusion-threading-in-python">An Intro to Threading in Python — Real Python</a></p><p>· <a href="https://www.youtube.com/watch?v=LOfGJcVnvAk">Introduction to Threads — YouTube</a></p><blockquote><strong>GitHub repositories</strong></blockquote><p><a href="https://github.com/HenilMistry/PythonAndMe"><em>HENIL MISTRY</em></a></p><p><a href="https://github.com/Harshil2312/Pythonpracticales/"><em>HARSHIL PADASALA</em></a></p><blockquote><strong>Prepared by(MEDUIM PROFILES)</strong></blockquote><p><a href="https://medium.com/@henilmistry74496"><em>HENIL MISTRY</em></a></p><p><a href="https://medium.com/@harshilpadsala999"><em>HARSHIL PADASALA</em></a></p><p><em>PREET PADARIYA</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99d0c904aa32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Threading in Python]]></title>
            <link>https://preetpadariya.medium.com/threading-in-python-ddc5e78c3450?source=rss-9cdab6f882b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddc5e78c3450</guid>
            <dc:creator><![CDATA[Preet Padariya]]></dc:creator>
            <pubDate>Mon, 11 Apr 2022 17:37:32 GMT</pubDate>
            <atom:updated>2022-04-12T08:34:16.230Z</atom:updated>
            <content:encoded><![CDATA[<h3>Threading in Python(Part-1)</h3><blockquote><strong>What is Thread?</strong></blockquote><p>All programmers are familiar with writing a <strong>procedural program</strong> which refers to <strong>sequential execution</strong> of a program. A program can be described as the set of statements which we don’t need to dig up that in deep. A normal program which you have written till now, most probably they all have one start, one end point and execution sequence; unless you don’t have knowledge of threads. This simply means that your <strong>program has single life, single point of execution</strong> at any given time during execution.</p><p>A <strong>single thread</strong> is similar to <strong>sequential program</strong> described as earlier. A single thread is also having single point of execution and one start point and one end point. It is stated that at any given time during runtime of a thread, there exist only a single point of execution, which is always true.</p><blockquote><strong>Definition: A thread is a single sequential flow of control within a program.</strong></blockquote><p>A thread is a separate flow of execution. The <strong>real excitement</strong> surrounding threads is <strong>not about a single sequential thread</strong>. Rather, <strong>it’s about the use of multiple threads</strong> running at the same time and performing different tasks in a single program. This use is illustrated in the next figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*eaq7p6jNSp0_KOcXocgTkg.png" /><figcaption>Single Threading (<a href="https://www.iitk.ac.in/esc101/05Aug/tutorial/figures/essential/threads-single.gif">Reference</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*N-YjcdJLee8qaykrlEujug.png" /><figcaption>Multiple Threading (<a href="https://www.iitk.ac.in/esc101/05Aug/tutorial/figures/essential/threads-two.gif">Reference</a>)</figcaption></figure><p>For instance, a Web browser is an example of a multithreaded application. Within a typical browser, you can scroll a page while it’s downloading an applet or an image, play animation and sound concurrently, print a page in the background while you download a new page, or watch three sorting algorithms race to the finish.</p><p>Also, any kind of game is also an example of multi-threaded application because playing sound, showing graphics etc. different kind of works are being managed by multiple threads in one program to make games even smoother for players to play and enjoy.</p><blockquote><strong>A state of thread is a term which determines the fate of thread</strong></blockquote><p>A particular <strong>state of thread</strong> will decide that <strong>how</strong> this <strong>thread will proceed further</strong>. At any point of time, a thread can exist in following states.</p><p>· New</p><p>· Runnable</p><p>· Blocked</p><p>· Waiting</p><p>· Timed Waiting</p><p>· Terminated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*y15xy-mpfoclopIK63fxXA.png" /><figcaption>flow of thread(<a href="https://media.geeksforgeeks.org/wp-content/uploads/threadLifeCycle.jpg">reference</a>)</figcaption></figure><blockquote><strong>Life Cycle of a thread</strong></blockquote><p>1. <strong>New Thread:</strong> When a new thread is created, it is in the new state. The thread has not yet started to run when the thread is in this state. When a thread lies in the new state, its code is yet to be run and hasn’t started to execute.</p><p>2. <strong>Runnable State:</strong> A thread that is ready to run is moved to a runnable state. In this state, a thread might actually be running or it might be ready to run at any instant of time. It is the responsibility of the thread scheduler to give the thread, time to run. <br> A multi-threaded program allocates a fixed amount of time to each individual thread. Each and every thread runs for a short while and then pauses and relinquishes the CPU to another thread so that other threads can get a chance to run. When this happens, all such threads that are ready to run, waiting for the CPU and the currently running thread lie in a runnable state.</p><p>3. <strong>Blocked/Waiting state:</strong> When a thread is temporarily inactive, then it’s in one of the following states:</p><p>1. Blocked</p><p>2. Waiting</p><p>4. <strong>Timed Waiting:</strong> A thread lies in a timed waiting state when it calls a method with a time-out parameter. A thread lies in this state until the timeout is completed or until a notification is received. For example, when a thread calls sleep or a conditional wait, it is moved to a timed waiting state.</p><p>5. <strong>Terminated State:</strong> A thread terminates because of either of the following reasons:</p><p>1. Because it exits normally. This happens when the code of the thread has been entirely executed by the program.</p><p>2. Because there occurred some unusual erroneous event, like segmentation fault or an unhandled exception.</p><blockquote><strong>“Multi-tasking”, leading towards “multi-threading”</strong></blockquote><p>Let us just first understand the two terminologies “multi-tasking” and “multi-threading” over here.</p><p><strong>“Multi-tasking” is concurrent performance/progress of several task which leads to performance of multiple tasks at a same time.</strong></p><p>As we have discussed earlier that the beauty of thread is laying in multiple threads at a time and so, executing multiple tasks simultaneously is the concept of “multi-threading”. Since we are talking about executing multiple tasks simultaneously, we might face some of the difficulties while doing or trying to achieve “multi-threading” environment such as;</p><p>· First and for most, we need to make sure that <strong>concurrency must be achieved</strong> and somehow, we need to <strong>maintain</strong> <strong>context-switching</strong>.</p><p>· <strong>Writing and debugging the code</strong> which is made to achieve multi-threading, <strong>is difficult</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*ExdS8IwwQbClIr-fYcBQjQ.png" /><figcaption>Issues with Multithreading Programs(<a href="https://www.tutorialspoint.com.cach3.com/major-issues-with-multi-threaded-programs.html">references</a>)</figcaption></figure><p>However, we can deal with those issues. First of all, accept those issues as truth and let us first understand the types of multi-threading.</p><blockquote><strong>Multi-threading Environment</strong></blockquote><p>The basic overview has been already given to you in above section. In this section we will see that what are the types of multi-threading which we can achieve.</p><blockquote><strong>Process based multi-threading</strong></blockquote><p><strong>Executing several tasks simultaneously </strong>where each <strong>task is having separate independent program</strong> is called Process based multi-Threading.</p><p>Ex: While typing a program in the editor we can listen audio songs from the same system. Yet same time we can also download a file from internet.</p><p>All these tasks will be executed simultaneously and independent of each other hence it is process based multi-Threading. Process based multi-Threading is the best suitable at OS level.</p><blockquote><strong>Thread based multi-threading</strong></blockquote><p><strong>Executing several tasks simultaneously</strong> where each <strong>task is separate independent part of the same program</strong> is called Thread based multi-Threading, and each independent part is called Thread.</p><p>Thread based multi-Threading is <strong>best suitable</strong> at <strong>programmatic level</strong>.</p><p>Whether it is process based or thread based the <strong>main objective</strong> of the multi-Threading is to <strong>reduce response time of the system</strong> and to <strong>improve performance</strong>. The main important application areas of multi-Threading are</p><p>1. To develop Multimedia Graphics</p><p>2. To develop animations</p><p>3. To develop video games</p><p>4. To develop web servers and application server etc.</p><p>In this whole section, we have briefed you about the thread. Now, you will be able to differentiate between thread, threading, multi-threading, multi-tasking, etc. Here are some key-words for you to summarise this whole section. From next section we will deep dive into programming.</p><blockquote><strong>Useful terms to remember</strong></blockquote><p>· Thread</p><p>· Life cycle of a thread</p><p>· Thread states</p><p>· Multi-tasking</p><p>· Multi-threading</p><p>· Process based multi-threading</p><p>· Thread based multi-threading</p><blockquote><strong>Conclusion of this part</strong></blockquote><p>We have learnt the basic concepts of thread and what is the basic definition and states of thread. The states and life cycle of a thread. We have also learnt that what is multi-tasking and multi-threading. Why we need multi-threading! What are the problems while we want to achieve multi-threading! What are the types of multi-threading and all that stuff? Now, you will be able to understand the upcoming programming-based implementation of the threading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddc5e78c3450" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>