Coder Social home page Coder Social logo

goconcurrency's Introduction

Go Concurrency

This repository contains two of the problems which are faced during concurrency, the Reader's Writer's problem and the Producer-Consumer problem. The problems are solved using:

  1. Channels in Go
  2. Mutex
  3. Wait Groups

Channels in Go: Channels in Go can be called as pipes which allow two different Go Routines to send data back and forth and using channels we can also attain a certain level of synchronization in go because some operations in channels are blocking. There are 2 types of channels in Go.

  1. Unbuffered Channels: These are used for asynchronous communication and are blocking in nature. So, if we send a value into the channel, it has to be received by another go routine to unblock the sender's go routine.
    Syntax:
    a:=make(chan int)
    
  2. Buffered Channels: These are used for Asynchronous communication and are non-blocking in nature, and we can specify their sizes. But, once a buffered channel is full it block any operation after it until a value has been received from that channel.
    Syntax:
    a:=make(chan int, 3)// making a buffered channel of capacity 3
    

The channels were mainly used in the Producer-Consumer problem. Where a buffered channel is made and the producers keep on producing items into that channel and consumer consumes the data from that channel. It should comply with the following rules:

  1. Producer should not produce if the channel is full.
  2. Consumer should not consume if the channel is empty.
  3. The buffer should not be accessed by the producer and consumer at the same time.

The producer and consumer problem has the main problem of synchronization. Where the producer should produce and only the should it be consumed by the consumer. So this is where channels help us solve this problem. We can wait on channels until a value is pushed into it so that it can be retrieved by the other go routine which was waiting to get the value from the channel.

goconcurrency's People

Contributors

sahaaj 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.