What is the difference between lightweight concurrency and heavyweight concurrency?

I'm just learning multithreaded programming, but the question here is a very basic concept that needs to be clarified first.

As I searched on the Internet, I understand that Heavyweight refers to the “process”, and Lightweight refers to the “flow”. However, why is the process difficult? due to lack of memory or something else?

+4
source share
2 answers

A “heavy weight” concurrency is where each of the simultaneous performers is expensive and / or has a lot of overhead.

A “light weight” concurrency is where each of the competing artists is cheap to start with and / or has little overhead.

Processes are generally more expensive to manage the OS than threads, since each process requires an independent address space and various control structures, while threads within the process share these structures.

Consequently, processes are considered heavyweights, while flows are light.

However, in some contexts, threads are considered heavyweights, and a “lightweight” concurrency object is a kind of “task.” In these contexts, the runtime typically performs these tasks in the thread pool, pausing them to block and reuse threads for other tasks.

+3
source

Currently, the “heavy” classification no longer has the same weight as before, while the advantage of separation of processes has not lost any of its potentials; -)

This is all thanks to the semantics of copy-on-write; during fork() pages from the parent will no longer be blindly copied to the child process. Both processes can work with shared memory until the child process starts writing to one of the shared memory pages.

Of course, creating more processes has a higher tendency to be limited to the operating system, since process identifiers are a more limited resource than threads.

0
source

All Articles