<p>How to decide whether to use threads or create separate process altogether in your application to achieve parallelism.</p>

[{'answer_id': 62942, 'author': 'Matt Brandt', 'author_id': 7383, 'author_profile': 'https://Stackoverflow.com/users/7383', 'pm_score': 2, 'selected': False, 'text': "<p>Generally you should use processes when the individual execution streams don't need to share global data and you would like to have each protected from the other.</p>\n"}, {'answer_id': 62953, 'author': 'Krishna', 'author_id': 6995, 'author_profile': 'https://Stackoverflow.com/users/6995', 'pm_score': 2, 'selected': False, 'text': '<p>The degree of parallelism mainly depends on the physical processors / cores available on your machine. If you have a single-processor/core machine, then having seperate processes may cause too much overhead. Threads would generally be preferred in that case.</p>\n\n<p>If you have multiple cores/CPUs then depending on what each process/thread does, you may opt for processes if the overhead is justified. Processes obviously have a much better level of memory isolation than threads - but at the same time in Windows, processes are fairly heavy, compared to threads.</p>\n\n<p>Threads of course can share data in the same process - but again you would need to synchronize access to the shared data - to prevent corrupt state. Sharing data between processes is more involved, the overhead (which is greated than simple thread synchronization) depending on the mechanisms used such as Named pipes, custom sockets-based communication, using a remoting framework, shared file / database etc.</p>\n'}, {'answer_id': 62962, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 1, 'selected': False, 'text': "<p>In Windows, processes are heavier to create then threads. So if you have several smaller tasks a thread or thread pool would be better. Or use a process pool to recycle the processes. Also sharing state between processes is more work then sharing state between threads. But then again: Threads could destabilize a complete process taking other threads down with it. If you want to minimize the chance of that happening you could go for separate processes. .Net's AppDomains might be a middle ground between both. </p>\n"}, {'answer_id': 62967, 'author': 'Andrei', 'author_id': 2718, 'author_profile': 'https://Stackoverflow.com/users/2718', 'pm_score': 2, 'selected': False, 'text': '<p>A couple of links that could help you decide, I hope:</p>\n\n<p><s><a href="http://blog.labnotes.org/2006/08/29/why-processes-scale-better-than-threads/" rel="nofollow noreferrer">http://blog.labnotes.org/2006/08/29/why-processes-scale-better-than-threads/</a></s>\n<a href="http://www.jroller.com/cpurdy/entry/fastcgi_not_so_fast" rel="nofollow noreferrer">http://www.jroller.com/cpurdy/entry/fastcgi_not_so_fast</a></p>\n'}, {'answer_id': 62980, 'author': 'wvdschel', 'author_id': 2018, 'author_profile': 'https://Stackoverflow.com/users/2018', 'pm_score': 5, 'selected': True, 'text': '<p>Threads are more light weight, and for the making several "workers" just to utilize all availabe CPUs or cores, you\'re better of with threads.</p>\n\n<p>When you need the workers to be better isolated and more robust, like with most servers, go with sockets. When one thread crashes badly, it usually takes down the entire process, including other threads working in that process. If a process turns sour and dies, it doesn\'t touch any other process, so they can happily go on with their bussiness as if nothing happened.</p>\n'}, {'answer_id': 63510, 'author': 'Adam Tegen', 'author_id': 4066, 'author_profile': 'https://Stackoverflow.com/users/4066', 'pm_score': 3, 'selected': False, 'text': '<p>Processes have more isolated memory.  This is important for a number of reasons:</p>\n\n<ul>\n<li>It is harder for a single task to crash the other tasks.  </li>\n<li>More memory will be available per process.  This is important for large, high-performance applications like Apache or database servers, like Postgres.  This is important for both allocated memory and memory mapped files.</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/62921', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7086/']