Search code examples
javamultithreadingcpuprocessor

Number of processors for a multi threading program


We know that a processor can process only one thread at a time. So when we say multitasking on a single processor, means the processor switches between the threads/ processes and gives the end-user a feeling of multitasking. Related to it, I've some questions to better understand the concept of multi-threading -

  • I think, totally it will take the same amount of time to execute all the processes in switching manner and executing them one by one, am I right?
  • If yes, is there any benefit of dividing a task in multiple threads?
  • What does it mean, when we say quad-core, octa-core processor? Does it mean a system has 4, 8 processors respectively and it can process 4/ 8 threads at a time?

Solution

    • Yes, it will take the same amount of time. In fact, it will take a bit longer, because the switching takes time.

    • Dividing a task into multiple threads lets you use multiple processors.

      Also, the CPU isn't always the slowest thing. Imagine you have a chat server - you could use one thread for each client, and each thread would spend most of its time doing nothing (waiting for the user to type a message).

    • A quad-core processor has 4 cores. An octa-core processor has 8 cores. Cores are pretty much separate processors, but on the same chip instead of separate chips.