Skip to content

Instantly share code, notes, and snippets.

@Cijin
Cijin / unbuffered-channels-note-to-self.md
Last active April 11, 2022 06:28
Unbuffered Channel in Go

Unbuffered Channels

Before I talk about unbuffered channels, let me recap what channels are and how they help make concurrency easier in Go. Channels synchronize go routines as they send and recieve resources they need between each other. When declaring channel we use the make keyword along with the type of data that we are going to share.

Unbuffered and Buffered channels behave differently and understanding both will help you decide which one is more suitable in a given scenario.

Unbuffered channel is channel with no capacity to hold any value before it's recieved.

@Cijin
Cijin / mutexes-note-to-self.md
Last active April 11, 2022 06:29
Mutexes in Go

Mutexes

A mutex is named after the concept of mutual exclusion. Which is what they do as well. They lock a block of code till execution is complete for another go routine to access it.

Example from Go In Action:

package main

import (
@Cijin
Cijin / yield-processor-note.md
Created March 15, 2022 01:55
Yield Processor: Note to future self.

When reading about Race conditions in go, I came across runtime.gosched() which I glanced over but did not clearly understand. So went through the docs to understand what it does. This is what the docs says it does:

Gosched yields the processor, allowing other goroutines to run. It does not suspend the current goroutine, 
so execution resumes automatically.

When I read this, I did not clearly understand what it does, cause I did not understand what yield meant. This is the best definition that made sense in this context: To give over possession of, as in deference or defeat; surrender.