Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What the difference between lightweight concurrency and heavyweight concurrency?

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?

like image 675
everx Avatar asked Jun 11 '12 07:06

everx


People also ask

What is lightweight and heavyweight 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.

What is lightweight and heavy thread?

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.

Why thread is lightweight and process is heavyweight?

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.

In what scenario thread becomes heavy weight?

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.

What is the difference between heavy-weight and light-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.

How does concurrency increase the amount of work done?

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.

What is the difference between switched LWP and heavy weight LWP?

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.

What is the difference between concurrency and parallelism?

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.


2 Answers

"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.

like image 126
Anthony Williams Avatar answered Oct 13 '22 13:10

Anthony Williams


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.

like image 37
Ja͢ck Avatar answered Oct 13 '22 13:10

Ja͢ck