'Does user level threads take advantage of multiprocessing?
Does user level threads take advantage of multiprocessing ? I read one such answer here. But, it's not clear though.
What does it mean by "user threads cannot take advantage of multithreading or multiprocessing"?
And one other answer here says that it is possible
Am I missing something here with some important details ?
Solution 1:[1]
Usually, user-level threads
, cannot take advantage of multiprocessing whereas, kernel-level threads
can take advantage of it.
It simply means that we can run several kernel-level threads
, in parallel on a multi-core
computer system. But the same cannot be done for user-level threads
.
This is possible because kernel-level threads
are managed by the Operating System
, whereas, the user-level threads
are managed by the user, meaning the OS is only aware of single user-level thread
(the executing one), even when there are actually more than one.
Now in your links, you provided it is mentioned that:
Some implementations base their user threads on top of several kernel
threads, to benefit from multi-processor machines (M:N model).
From what I understood after reading the links is that its possible for user-level threads
to take advantage of multiprocessing
, only if its implementation specific. So this would basically be like a kernel-level thread
associated with a core
and a user-level thread
associated with the respective kernel-level thread
.
So in the end, its after all the kernel-level threads
running parallel on several cores(OR CPU's)
. We can't take advantage of multiprocessing
without any assistance from kernel
.
Solution 2:[2]
It depends upon how you define "take advantage."
User threads are scheduled by the process. The process is scheduled by the kernel.
A user thread can then only execute on the process in which the process is scheduled.
Thus a user threads from the same process cannot execute on multiple processors concurrently. They execute interleaved.
If that is your definition of multi-processing, your answer is NO.
However, if the OS supports it, the process can execute on any available processor. Thus, a user thread can execute on any available processor.
If that is your definition of multi-processing, your answer is YES.
Solution 3:[3]
But if user level threads cant take advantage of multiprogramming(multiple cores) why would we use them ? It is in fact consuming more time !!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sumeet |
Solution 2 | user3344003 |
Solution 3 | BT19ECE024 Ajinkya |