resources: https://www.youtube.com/watch?v=LvgVSSpwND8
concurrency is the ability of the program to run different parts of the program at any order and the program output does not change not necessarily running them simultaneously , it is not same as parallelism which is running multiple things at simultaneously
to run multiple parts of the program in concurrent we use go routines
processes : a process is set of instructions that are currently been execute by CPU, CPU allocates some resources such as memory, and makes sure that other processes can’t access it
threads : are the smallest units of execution, the can be compared to workers , they are used to perform a independent task within a process, a process can have more then one threads, threads within the process share the same memory and can easily communicate
Go routines: are light weight concurrent unit that are managed by go runtime
"Concurrent units" refer to independent, concurrently executing components within a program
using go keyword we can create a new go routine which is run concurrently
example:
go func() {
}()
here this function is called as a anonymous functions we are calling the function as we create it using () at the end, here go creates a new go routine which is run independently from the main process
when multiple go routines try to write date into a data structure such as a map, slice or a variable a race condition in generated and an error is raised