<?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 Mihindu Ranasinghe on Medium]]></title>
        <description><![CDATA[Stories by Mihindu Ranasinghe on Medium]]></description>
        <link>https://medium.com/@mihinduranasinghe?source=rss-868caa4d5bc3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j-x0_v0Qvl8CkcmunL4FKw.png</url>
            <title>Stories by Mihindu Ranasinghe on Medium</title>
            <link>https://medium.com/@mihinduranasinghe?source=rss-868caa4d5bc3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:42:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mihinduranasinghe/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[Leta OS. By Mihindu Ranasinghe]]></title>
            <link>https://medium.com/@mihinduranasinghe/leta-os-by-mihindu-ranasinghe-454cd09ac8d1?source=rss-868caa4d5bc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/454cd09ac8d1</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[assembl]]></category>
            <category><![CDATA[os]]></category>
            <category><![CDATA[nasm]]></category>
            <category><![CDATA[qemu]]></category>
            <dc:creator><![CDATA[Mihindu Ranasinghe]]></dc:creator>
            <pubDate>Fri, 14 Jun 2019 07:27:16 GMT</pubDate>
            <atom:updated>2019-06-14T18:44:24.002Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What is “Leta OS” ?</strong></h3><p><strong><em>“Leta OS”</em></strong> is a simple OPERATING SYSTEM written in <strong>ASSEMBLY LANGUAGE</strong>. The main task of this OS is to display the hardware information of your personal computer where you run this operating system.</p><p>(Leta is a university nickname/card which was reasoned to give this OS a name like Leta OS)</p><p>Leta OS contains three separate windows as <strong>welcome page</strong>, a <strong>menu windows</strong> to select what you need to perform and <strong>hardware information displaying window</strong>.</p><p>Here i have developed this operating system that enables the capability to boot this OS through <strong><em>CD rom, USB, floppy disk</em></strong> or can be run this OS in a <strong><em>virtual machine box(QEMU) </em></strong>on linux or windows.</p><h4>👏DOWNLOAD:</h4><h4>You can download “LetaOS” from my github.</h4><p>👉👉👉<a href="https://github.com/mihinduranasinghe/LetaOS.ByMihinduRanasinghe"><em>LetaOS.By-Mihindu_Ranasinghe</em></a></p><p><a href="https://github.com/mihinduranasinghe/LetaOS.ByMihinduRanasinghe">mihinduranasinghe/LetaOS.ByMihinduRanasinghe</a></p><h3><strong><em>How to boot “Leta OS” ?</em></strong></h3><p>After you have downloaded my Leta OS folder, open disk_images/ directory and you will be displayed these files, these images that you can write to a real device(pen/floppy disk, CD)</p><ul><li>LetaOS.iso- CD ISO image built using floppy disk image</li><li>LetaOS.flp -Floppy image of LetaOS</li></ul><p>Linux kernel uses ordinary files format to represent various I/O devices and these files are in <em>/dev </em>directory. You just need the device, /dev/sdb, rather than the number (**/dev/sdb1). <br><strong>(sdb</strong>-represents the device ,<strong>sdb1</strong>-primary partition on that device)</p><p>Then enter(in disk image directory),</p><pre>sudo dd if=LetaOS.flp of=/dev/sdb</pre><p>NOTE: Format your USB drive. Try not to partition your pen drive and make it as LetaOS only USB drive.</p><p><em>: sudo /sbin/mkdosfs -F 32 -I /dev/sdb</em></p><p>On linux, use the dd utility like this:</p><pre>sudo dd if=LetaOS.flp of=/dev/fd0</pre><p><strong><em>Using Emulator:</em></strong></p><p>If you want to quickly try out “Leta OS” you can use an emulator/virtual thing to experience Leta OS. That doesn’t involve writing disk images to a physical device.</p><ul><li><strong>QEMU</strong>- <a href="https://www.qemu.org/">https://www.qemu.org</a> (This is what i recommend to try in both Linux and windows)</li><li><strong>NASM</strong>- Nasm is a assmbler that compiles assembly language code into machine language. Download these two tools into your linux machine to work with Leta OS</li></ul><p>👏NASM &amp; QEMU installation on linux:(both will be installed at once)</p><pre>sudo apt-get install build-essential qemu nasm</pre><p>👏Next: Open Leta OS folder and open that location in the terminal and compile Leta OS like this and <strong>it will be built</strong>,</p><pre>sudo bash ./build-linux.sh</pre><p>👏Running:After building LetaOS type this command in that same location on the terminal , <strong>OS will be turned on in qemu emulator:</strong></p><pre>qemu-system-i386 -soundhw pcspk -drive format=raw,file=disk_images/LetaOS.flp,index=0,if=floppy</pre><h3><strong>This is how “Leta OS” looks like:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*njR5lSDbcCqkGiNzPiyXhw.png" /><figcaption>Welcome Screen of LetaOS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*p3JLdndrtOSPbf6dia4EDw.png" /><figcaption>Second Screen/Window to select Hardware info option of LetaOS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*28Od9yYr_JekicDHrB8srg.png" /><figcaption>Hardware Information Display on Leta OS</figcaption></figure><h3>Leta OS:</h3><p>There are some special parts of my LetaOS code.</p><ol><li>Created three separate windows with basic Assembly.</li></ol><p>(Draw backgrounds, option screens are coded with text contents ,dialog boxes, created buttons to perform something once it clicked, made color variations and designed UI with three separate windows)</p><ul><li>kernal.asm</li><li>screen.asm</li></ul><p>2. Shut down method/Turn off OS once you click shut down button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*uVQHI5Sd-XtZvaVEjFCeYg.png" /><figcaption><strong>OS ShutDown</strong></figcaption></figure><p>3. Used BIOS service interrupts/processor and hardware interrupts to display hardware information.</p><ul><li>BIOS Interrupts</li><li>CPU Interrupts</li><li>Number Of Hard Drives</li><li>Reading base memory</li><li>Display all the Hardware information in one screen</li></ul><p><strong>Hardware interrupts</strong> are used by devices to communicate that they require attention from the Operating System. They are implemented using electronic alerting signals that are sent to the processor from an external device, which is either a part of the computer itself. They have a direct line to the processor through an interrupt request line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/0*JCmzjnyHMerGn-ND.PNG" /><figcaption><strong>Interrupts</strong></figcaption></figure><p>4. Enabled keyboard inputs such as ENTER, ESC, ARROWKEY inputs to perform click, back and move between buttons.</p><h3>Thank You</h3><p>Hope you all enjoyed and learned something on this. Please let me know your comments suggestions and any questions you have about this blog.</p><p><a href="https://github.com/mihinduranasinghe/LetaOS.ByMihinduRanasinghe">mihinduranasinghe/LetaOS.ByMihinduRanasinghe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=454cd09ac8d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dinning Philosopher Problem]]></title>
            <link>https://medium.com/@mihinduranasinghe/dinning-philosopher-problem-a88ba358fcf0?source=rss-868caa4d5bc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a88ba358fcf0</guid>
            <category><![CDATA[dining-philosophers]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oop]]></category>
            <dc:creator><![CDATA[Mihindu Ranasinghe]]></dc:creator>
            <pubDate>Sat, 04 May 2019 13:41:11 GMT</pubDate>
            <atom:updated>2019-05-04T14:29:05.176Z</atom:updated>
            <content:encoded><![CDATA[<p>The dinning philosopher problem,invented by <strong>Edster Dijkster</strong> is the classic demonstration of deadlock. The Dinning Philosopher problem used to describe synchronization issues in a multi-threaded environment and illustrate techniques for solving them.</p><p>The basic description specifies five philosophers(or any number) sitting around around a circle table ,spending time eating and thinking. There are only five forks for them(for five philosophers) on the table between plates. A philosopher needs to have forks in both his hands to be able to eat. After eating he puts both of them down think for a while and forks can be picked by another who repeats the same procedure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*VN-B98V2RO_gKFcppOdItQ.jpeg" /><figcaption>Dinning Philosophers Table with five forks and five plates</figcaption></figure><h3>Note:</h3><p>Imagine that all the philosophers pick their right side(same side) fork at the same time, then all of them will have only one fork on their hands . They will not be able to eat anymore. This is what we call as a <strong>Dead Lock. </strong>Our goal is to come up with a solution that helps the philosophers achieve their goal of eating and thinking without getting starved to death.</p><p>We are going to find solution to this problem using <strong>Semaphore</strong></p><p><strong>Semaphore:</strong></p><p>Semaphore is an abstract data type or a variable used to control access to a common resources by multiple processes in a concurrent system such as a multitasking operating system. This concept is used to solve critical section problem by using two atomic operations.</p><p><strong>Wait</strong> and <strong>Signal</strong> that are used for process <strong>synchronization</strong>.</p><h3>Solution</h3><p><strong>In this solution, each of the philosophers follow the following protocol:</strong></p><p><em>While(the conditions is true){</em></p><ul><li><em>Think…</em></li><li><em>pick up left fork()(Think until the right one is available)</em></li><li><em>pick up right fork ()</em></li><li><em>eat() for a fixed amount of time</em></li><li><em>put down right fork()</em></li><li><em>put down left fork()</em></li><li><em>back to the thinking…</em></li></ul><p><em>}</em></p><h4>Implementation</h4><p>we model each of our philosophers as classes that implement the Runnable interface so that we can run them as separate threads. All of them have the access to both forks on his left and right.</p><p>Also, there is another method that instructs a philosopher to perform his preferred action:</p><ul><li>eat, think , getting forks to eat</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*zuqD9O0a4ng11tPeUjhLCg.png" /></figure><p>The execution order is not enforced by time alone.</p><p>To simulate acquiring a fork, we need to lock it so that no two philosopher threads acquire it at the same time.We use the synchronized keyword to acquire the internal monitor of the fork object and prevent other threads from doing the same to achieve this.</p><p>This is done in <strong><em>run() </em></strong>method in Philosopher class.</p><ul><li>A philosopher think for a while and then decides to eat. timestamps were added to each action, in order to understand the order in which event occur.</li></ul><p>To operate the whole process, we write a <strong>Main method</strong> that creates 5 philosophers (or any number of philosophers) as threads and start all of them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*AiW73uyN265f0h2rgaoi3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*dKkboUFXezP9wD2ZyNsb-Q.png" /></figure><p>The output of this program :</p><p>Running this code results in an output similar to the following. Your output will most likely differ because of the sleep() method invoked for a different interval</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*x7lzBl_bSpvz-yESEie9bw.png" /></figure><p><strong>Resolving the Deadlock</strong></p><p>A deadlock is a situation where the progress of a system is halted as each process is waiting to acquire a resource held by some other process.</p><pre>if(j == philosophers.length - 1){<br>    //The last philosopher picks up the right fork first<br>    philosophers[j] = new Philosopher(rightFrk, leftFork);<br>}else{<br>    philosophers[j] = new Philosopher(leftFork, rightFrk);<br>}</pre><p>Above code is used in the <strong>Main Method </strong>to avoid the deadlock. We have mentioned what deadlock is in a previous paragraph in this article.</p><p>It can be verified by running the code several times, that the system is free from the deadlock situation that occurred before.</p><p>philosopher reach for his right fork first, instead of the left. This breaks the circular wait condition and we can avert the deadlock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*dKkboUFXezP9wD2ZyNsb-Q.png" /></figure><h3>You all can clone and download my code:</h3><p><a href="https://github.com/mihinduranasinghe/DinningPhilosopherProblem">mihinduranasinghe/DinningPhilosopherProblem</a></p><p>Hope you all enjoyed and learned something on this. Please let me know your comments suggestions and any questions you have about this blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a88ba358fcf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>