Code Monkey home page Code Monkey logo

bounded-buffer-problem's Introduction

Purpose

The purpose of the project is to design a multi-threaded program with use of semaphore and mutex to avoid deadlocks

Technologies

  • POSIX Threads

Process

Step 1: The Language of Choice

The project involves use of a processor which sits at the core of a computer. To get to the core, a programming language must be low-level, which means it must provide little or no abstraction of programming concepts and be very close to writing actual machine instructions. My language of choice was C as it is a low-level language and supports multi-threaded programming with POSIX threads library.

Step 2: The Understanding of Multi-threading

The very first step I took before delving into coding was understanding the concept of multi-threading. Essentially, it is a programming model that divides the processor to perform different tasks at the same time. In other words, a program or an operating system process manages its use by more than one user at a time and multiple requests by the same user without having to have multiple copies of the programming running in the computer. Multi-threaded programs can help with improving the performance of a device or even allow adding new features without the need to change or upgrade the processor.

Step 3: The Implementation

To create the program, I first needed to create two groups of threads – worker thread and consumer thread. The worker threads pick a tool from one resource, create a new product with a material randomly generated from other resource and pushes a complete product into anther resource. Then, the consumer threads use a product created by a worker thread. As both types of threads share a common resource such as an array, semaphore and mutex which work as a key to control access to the common resource.

Step 4: Final Result & Evaluation

As a result, threads continued to produce and consume materials from a common resource without a deadlock (different threads are blocked to access the common resource, think it as a traffic jam at a 4-way intersection). I learned that multi-threaded programming efficiently uses the computer processor to do more than one tasks at a time. However, the design format of outputs could’ve been built better in a way that it only shows changing materials from resources. The current program displays outputs whenever a thread is executed even if there is no change in material from any resource.

bounded-buffer-problem's People

Contributors

dleedev365 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.