Understanding how the CPU works and how to write thread-efficient programs

1️⃣ Thread Context Switching :
When a program is executed in a single-core CPU, the CPU can work with and execute only one thread at any given time. Each thread gets its share of CPU time. For example, when a thread is writing something to the disk, and if it's consuming time, the CPU switches to another thread while the earlier thread is waiting. Threads are context-switched, and it looks like it is multitasking, and things are going on in parallel, which is not.

2️⃣ Processing :
✅️ Sequential processing : is where programs are executed in a sequence, one by one, getting allocated with the CPU
✅️ Concurrency : Parts of the program can be run independently and combined for the result and to speed up the execution on a single CPU
✅️ Parallel : Each program can be run on each CPU independently and combined for the final results to speed up the execution

3️⃣ Single Vs. Multi-thread :
By running multiple threads vs. single threads to execute a program, the overall execution time can be reduced, and efficiency can be improved.

4️⃣ Process Vs. Threads :
A process uses CPU, memory, disk, and other resources to execute a program. A process can spin up one or multiple threads to complete the job.

5️⃣ Sync Vs Asyn :
Sync is executed in a sequence and cannot be skipped, but Asyn can run its block of the program separately from the main program and doesn't have to wait for completion to move on

6️⃣ Thread Deadlock :
When the resources required by a thread are being blocked by another one, and each one is waiting on another one, it leads to a deadlock state