I just learn multiple threading programming, but the question here is a very basic concept need to be clarified first of all.
As I searched from internet, what i understand is Heavyweight is regarding to "process", and Lightweight maps to "thread". However, why process is heavyweight? because of non-sharing memory or something else?
Heavy-weight process defines the processes running parallel to accomplish their tasks. Every process has their own data,code and OS resources and the processes requires extra resources to communicate between themselves. Light-weight process has more advantage than Heavy-weight process.
Threads are typically compared in terms of processing time. For example, a lightweight thread is a thread that takes less processing time, whereas a heavyweight thread is a thread that requires more processing time.
Threads are sometimes called lightweight processes because they have their own stack but can access shared data. Because threads share the same address space as the process and other threads within the process, the operational cost of communication between the threads is low, which is an advantage.
Answer : Threads are lightweight process only if threads of same process are executing concurrently. But if threads of different processes are executing concurrently then threads are heavy weight process.
Heavy-weight process defines the processes running parallel to accomplish their tasks.Every process has their own data,code and OS resources and the processes requires extra resources to communicate between themselves. Light-weight process has more advantage than Heavy-weight process.
It increases the amount of work finished at a time. In the above figure, we can see that there is multiple tasks making progress at the same time. This figure shows the concurrency because concurrency is the technique that deals with the lot of things at a time.
Switching from one LWP to another is much faster than switching from one heavy-weight process to another, because there is less to manage, and the MMU is not involved. Show activity on this post.
Concurrency is the task of running and managing the multiple computations at the same time. While parallelism is the task of running multiple computations simultaneously. 2. Concurrency is achieved through the interleaving operation of processes on the central processing unit (CPU) or in other words by the context switching.
"Heavyweight" concurrency is where each of the concurrent executors is expensive to start and/or has large overheads.
"Lightweight" concurrency is where each of the concurrent executors is cheap to start and/or has small overheads.
Processes are generally more expensive to manage for the OS than threads, since each process needs an independent address space and various management structures, whereas threads within a process share these structures.
Consequently, processes are considered heavyweight, whereas threads are lightweight.
However, in some contexts, threads are considered heavyweight, and the "lightweight" concurrency facility is some kind of "task". In these contexts, the runtime will typically execute these tasks on a pool of threads, suspending them when they block, and reusing the threads for other tasks.
Nowadays the "heavy" classification no longer carries the same weight as it used to while the advantage of process separation has lost none of its potency ;-)
This is all thanks to the copy-on-write semantics; during a fork()
the pages from the parent are no longer blindly copied for the child process. Both processes can operate using shared memory until the child process starts to write into one of the shared memory pages.
Of course, creating more processes has a higher tendency of being limited by the operating system as process ids are a more limited resource than threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With