Question

Possible Duplicate:
Why should I use a thread vs using a process?

I have some long-running tasks, they consume cpu and memory heavily. Should I run them in another thread or another process? And what is the benefit of each option?

Was it helpful?

Solution

It depends what operations you're trying to do.

In addition to what Why should I use a thread vs. using a process? mentions, I would like to add that threads share the memory of the process they are part of. On the other hand, processes don't share memory. Each process has its own memory space on the stack.

If you plan on working on the same data (perhaps operations on parts of it), I recommend you do so with threads. Have each thread work on a chunk of data.

If the operations are totally unrelated, use processes. I know this is kinda vague; but if you don't share data and operations are not to be serialized, you could use processes.

Normally, one application (process) spawns multiple threads. If you have multiple applications, each application is a process and has its own address space.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top