Basics of threads

What is thread?

Threads can be thought of as smaller units within a process. Consider making a pizza: you cut vegetables, prepare the dough, and preheat the oven. In this scenario, the overall process is making the pizza, while the steps like cutting vegetables and preparing the dough are the threads.

Why do we need multithreading?

Imagine you're organizing a big birthday party. You have to do many things like bake a cake, decorate the room, and send invitations. If you did everything by yourself one at a time, it would take forever. But if you get help from your friends and family, you can divide the tasks among them. Someone bakes the cake, another person decorates the room, and someone else sends the invitations—all at the same time. This way, everything gets done faster and the party is ready sooner. Multithreading in computers works the same way. Instead of one part of the computer doing all the work step by step, it divides the work into smaller tasks called threads. These threads can run at the same time, so everything gets done faster and more efficiently. This makes the computer programs run smoother and quicker, just like your birthday party gets ready faster with everyone helping out.

If a computer is octa-core, then a process can be divided into 8 threads only?

Not exactly. While having an octa-core (8-core) processor means your computer can run up to 8 threads truly concurrently, you are not limited to only creating 8 threads. You can create many more threads than the number of cores. However, having more threads than cores means that the operating system will need to manage the threads, often by switching between them, so not all threads will be running at the same time.

Multi-tasking vs Multi-threading



Thread context-switching vs Process context-switching











Comments

Post a Comment

Popular posts from this blog

Indexed allocation

Thrashing

Basics of paging