Giter VIP home page Giter VIP logo

go-concurrency-mutex's Introduction

go-concurrency-mutex

Mutex

Mechanism that allow us to prevent concurrent processes from entering a critical section or that's already been executed by another process.

image

Description of the problem

image

馃摌 Imagine we have Gopher with a bank balance of a $1000 to start. then Gopher tries to add $ 500 to this account Now one go routine would see this transaction, read the value of a $1000 and proceed to try and add $500 to that account. That balance however at the exact same moment a charge of $700 as applied to pay his mortgage (hipoteca) and the second proccess reads the inital value of the $700 before the first is able to add the additional deposit of $500 and it then proceeds to substract $700 from a $1000. Now the customer then checks his bank balance the next day, and notices that he is down $300. As the second process was unaware of the first deposit and overrruled the value upon completion of that second goroutine. So now that we know what the problem is let'see how we can fix it using a mutex

馃摌 Tenemos a Gopher que tiene en su cuenta, un balance de $1000. Quiere depositar $500, entonces una rutina va a leer el balance inicial y hacer el dep贸sito de dicho monto. Sin embargo, al mismo tiempo, se le aplica una extracci贸n de $700 para pagar su hipoteca. Este segundo proceso, lo que hace es leer su dep贸sito inicial $1000 y retirar los $700 respectivos. Al otro d铆a, Gopher chequea su cuenta y nota que tiene un balance de solamente $300 a favor.

image

Con Mutex, podemos solucionar este problema.

go-concurrency-mutex's People

Contributors

jonathanbs9 avatar

Watchers

 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.