Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can multithreading be implemented on a single processor system?

I have always followed the concept that multithreading can only be implemented on multiple processors system where there are more than one processor to be assigned to each thread and each thread can be executed simultaneoulsy. There is no scheduling in this case as each of the thread has separate resources all dedicated to it. But I recenetly read it somewhere that I can do multithreading on single processor system as well. Is it correct? and if yes then what is the difference between single processor and multiple processor systems?

like image 377
Ayse Avatar asked Apr 20 '13 05:04

Ayse


People also ask

What can be used to implement multithreading on a single processor multiplexing?

On a single processor, multithreading generally occurs by time division multiplexing (as in multitasking) the processor switches between different threads. This context switching generally happens so speedy that the user perceives the threads or tasks as running at the same time.

How many threads can run on a single processor?

A single CPU core can have up-to 2 threads per core. For example, if a CPU is dual core (i.e., 2 cores) it will have 4 threads. And if a CPU is Octal core (i.e., 8 core) it will have 16 threads and vice-versa.

Does multithreading require multiple cores?

Multithreading refers to a program that can take advantage of a multicore computer by running on more than one core at the same time.


2 Answers

Of course it can be done on a single-processor system, and in fact it's much easier that way. It works the same way as running multiple processes -- the kernel, via a timer interrupt or other similar mechanism, suspends one, saving its machine state, and replacing that by the previously-saved state of another -- the only difference being that two threads of the same process share the same virtual memory space, making the task-switch much more efficient.

Multi-threading on multi-processor systems is actually much more difficult, since you have issues of simultaneous access to memory from multiple cpus/cores, and all the nasty memory synchronization issues that arise out of that.

like image 163
R.. GitHub STOP HELPING ICE Avatar answered Oct 14 '22 15:10

R.. GitHub STOP HELPING ICE


I recenetly read it somewhere that I can do multithreading on single processor system as well. Is it correct? and if yes then what is the difference between single processor and multiple processor systems?

Yes you can do multithreading on a single processor system.

In multi-processor system , multiple threads execute , simultaneously on different cores. Eg- If there are two threads and two cores , then each thread would run on individual core.

In a single-processor system, multiple threads execute , one after the other or wait until one thread finishes or is preempted by the OS , depending on the thread priority and the OS policy.But the running threads , gives an illusion that they run simultaneous , relative to the required application response time of the User space application.

Time Comparison(Example):

if two threads take 10us each to execute, then on a 2 processor system , the net time take is 10us

if two threads take 10us each to execute, then on a 1 processor system , the net time take is 20us

like image 39
Barath Ravikumar Avatar answered Oct 14 '22 16:10

Barath Ravikumar