Are threads more efficient or creating a sub process more efficient in c where execution of parts of code is independent of other and which is efficient while writing code for a server to handle requests  i am trying to figure out weather sub process is more useful or threads, when we have to execute  parts of single program in parallel on a server based on the requests from clients. i have read both disadvantages and advantages of threads and sub process.When i have parts of code that have to be executed in parallel and each part is independent of other which one is preferred a sub process or thread and why  i have found some delay in execution while using fork() system call but thread is fine and when one thread caused error will it effect other thread
9078
What is the technical difference between a process and a thread?  I get the feeling a word like 'process' is overused and there are also hardware and software threads. How about light-weight processes in languages like ? Is there a definitive reason to use one term over the other?
21181
What is the maximum number of threads that can be created by a process under Linux?  How (if possible) can this value be modified?
17715
When writing multithreaded applications, one of the most common problems experienced is race conditions.    My questions to the community are:  What is the race condition? How do you detect them? How do you handle them? Finally, how do you prevent them from occurring?
44009
Is there a realistic way of implementing a multi-threaded model in PHP whether truly, or just simulating it. Some time back it was suggested that you could force the operating system to load another instance of the PHP executable and handle other simultaneous processes.  The problem with this is that when the PHP code finished executing the PHP instance remains in memory because there is no way to kill it from within PHP.  So if you are simulating several threads you can imagine whats going to happen.  So I am still looking for a way multi-threading can be done or simulated effectively from within PHP. Any ideas?
72672
I get how a normal fork bomb works, but I don't really understand why the &amp; at the end of the common bash fork bomb is required and why these scripts behave differently:  :(){ (:) | (:) }; :   and   :(){ : | :&amp; }; :   The former causes a cpu usage spike before throwing me back to the login screen. The latter instead just causes my system to freeze up, forcing me to hard reboot. Why is that? Both continually create new processes, so why does the system behave differently?   Both of the scripts also behave differently from  :(){ : | : }; :   which doesn't cause any problems at all, even though I would have expected them to be alike. The bash manual page states that the commands in a pipeline are already executed in a subshell, so I'm led to believe that : | : should already suffice. I belive &amp; should just run the pipeline in a new subshell, but why does that change so much?  Edit: Using htop and limiting the amount of processes, I was able to see that the first variant creates an actual tree of processes, the second variant creates all the processes on the same level and the last variant doesn't seem to create any processes at all. This confuses me even more, but maybe it helps somehow?
113923
What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that.
97854
I have a dual core core i5 with hyperthreading. Since hyperthreading allows for unused cpu time to be used by other processes, why would this make it seem like 4 logical processors (2 per actual core). How is this different than out of order execution?  Lets say core0/core1 are one core and core2/core3 are another. If core0 and core2 are at 100% is my cpu at 100% load or only 50%? If all of them are at 100%, what does that entail? Also, how come processes tend to execute on core0 and core2 rather than core1 and core3?
45500
I developing a simple real-time strategy game in a small team with no experience, and we're considering using one thread per game object (tank, soldier, etc). Is this a good idea or is it overkill?  The thread would call each object on each instant change (game timer, not graphic engine timer)  We're using Python with the Panda3D engine, meaning the GIL is probably going to reduce a lot the possible speed improvements.
24683
I was wondering how to understand the following:     Piping the stdout of a command into the stdin of another is a powerful   technique. But, what if you need to pipe the stdout of multiple   commands? This is where process substitution comes in.   In other words, can process substitution  do whatever pipe can do?   What can process substitution do, but pipe cannot?
85551
I have a very large query (~630 lines) that involves a lot of nested SELECT statements and pulls from multiple views. Our SQL server has parallelism set to 2 with a threshold of 95 (set that way because our DBA was optimizing it based on some other applications). This query has recently started taking 5-10 minutes to complete, up from usually less than a minute. While investigating the cause, we noticed that it never seems to trigger parallelism, always running serial, and suspect that may have something to do with its performance. What's weird is while experimenting, we even dropped the threshold back down to the default value of 5 seconds, and it still won't run parallel. What could be preventing it?  We've been doing the testing on a non-production environment that nobody else was using at the time, so this was the only query being run. Our DBA also tried things like clearing caches and plans, and even recycling the system, but it had no effect.  Update 1: Per comments, I've verified that stats are updated nightly but the problem persists. We're actually rolling back the code to an earlier version that didn't have such serious performance issues, but will continue to test this code because it was supposed to improve performance over the old code, and actually did in initial testing. Will update here accordingly.
83950
I'm confused about the difference or advantage (if any) of running a set of tasks in a .sh script using GNU parallel  E.g. 's answer:  parallel ./pngout -s0 {} R{} ::: *.png   rather than say looping through them putting them in the background &amp;.  E.g. 's answer:  #copied from the link for illustration for stuff in things do ( something   with   stuff ) &amp; done wait # for all the something with stuff   In short are they just syntactically or practically different? And if practically different when should I use each?
105911
How to wait for multiple child processes in Python on Windows, without active wait (polling)? Something like this almost works for me:  proc1 = subprocess.Popen(['python','mytest.py']) proc2 = subprocess.Popen(['python','mytest.py'])     proc1.wait() print "1 finished" proc2.wait() print "2 finished"   The problem is that when proc2 finishes before proc1, the parent process will still wait for proc1. On Unix one would use waitpid(0) in a loop to get the child processes' return codes as they finish - how to achieve something like this in Python on Windows?
122116
We have a codebase that is several years old, and all the original developers are long gone.  It uses many, many threads, but with no apparent design or common architectural principles.  Every developer had his own style of multithreaded programming, so some threads communicate with one another using queues, some lock data with mutexes, some lock with semaphores, some use operating-system IPC mechanisms for intra-process communications.  There is no design documentation, and comments are sparse.  It's a mess, and it seems that whenever we try to refactor the code or add new functionality, we introduce deadlocks or other problems.  So, does anyone know of any tools or techniques that would help to analyze and document all the interactions between threads?  FWIW, the codebase is C++ on Linux, but I'd be interested to hear about tools for other environments.    Update  I appreciate the responses received so far, but I was hoping for something more sophisticated or systematic than advice that is essentially "add log messages, figure out what's going on, and fix it."  There are lots of tools out there for analyzing and documenting control-flow in single-threaded programs; is there nothing available for multi-threaded programs?    See also
41441
I wonder what's the difference between a dual core computer and a computer with 2 processors on the mother board.. I think it's something related with the threads but a I don't understand it very well..
63591
According to : Access to the threads table does not require a mutex  and has minimal impact on server  performance. The other sources have negative performance consequences because they require a mutex.   So yes, I want to use threads table to examine running queries. The trouble is, the PROCESSLIST_INFO column does not contain the full query. It just contains a truncated version of the query. There is a flag viz performance_schema_max_sql_text_length which controls how many bytes are allocated for the SQL query. But it seems to affect the events_statements_history_long table. There is no change in the thread table output. There is also the events_statement_current table. But it is not clear if accessing that table affects performance or not.
78122
Please take a look on the following pseudo-code:  boolean blocked[2]; int turn; void P(int id) {       while(true) {              blocked[id] = true;              while(turn != id) {                     while(blocked[1-id])                     /* do nothing */;                     turn = id;              }              /* critical section */              blocked[id] = false;              /* remainder */       } } void main() {       blocked[0] = false;       blocked[1] = false;       turn = 0;       parbegin(P(0), P(1)); //RUN P0 and P1 parallel }   I thought that a could implement a simple Mutual - Exclution solution using the code above. But it's not working. Has anyone got an idea why?  Any help would really be appreciated!
11768
One of the first things I've learned about Java EE development is that I shouldn't spawn my own threads inside a Java EE container. But when I come to think about it, I don't know the reason.  Can you clearly explain why it is discouraged?   I am sure most enterprise applications need some kind of asynchronous jobs like mail daemons, idle sessions, cleanup jobs etc.  So, if indeed one shouldn't spawn threads, what is the correct way to do it when needed?