Concurrency Theory - LogeshVel/go_programs GitHub Wiki
Not all tasks can be parallelized
Concurrent
Process
OS
Scheduling Processes
Context Switching
Threads
Switching between the threads in a process is much faster than switching the Process. Since the Process has large context(state) to store and switch between Process by the OS
Goroutines
The OS will start the main thread, the switching between the Goroutines is handled by the Go Runtime scheduler
Interleaving
Leaving the execution of one task and jumps to execute next task. We never know at which point(instruction) the switch happens.
Race Condition
Simply, when multiple threads tries to access a resource at the same time the race condition occurs. Technically not same time since Concurrent executes one at a time, race condition occurs when one thread works with one data and before completing that work with that data the next thread started (context switching happened) and the new thread tries to modify/work with that data, again context switch happens now the old task continues its work but the shared data is altered/modified. This condition is race condition