Subj : Re: Futexes are wrong! (Are they?) To : comp.programming.threads From : David Butenhof Date : Wed Jun 08 2005 05:52 pm Jomu wrote: > David Schwartz wrote: > >> The point of threads is to keep multiple CPUs busy and to make blocking >>non-fatal to the process (so you don't have to write 100% of your code where >>any blocking is a total disaster). This gives you those important >>advantages. > > I still don't see how this eliminates (or at least dwarves) > competition as compared to colaboration. Compared to thread-per-client > design. Difference is still only in some order of magnitude. The point is that the THREADS are not "personifications" of the CLIENT; they're anonymous agents acting on behalf of all of the clients. The threads share resources (like malloc), but they COOPERATE to meet the server's requirements rather than COMPETING to meet individual client requirements. That is, you can shuffle your request queue to prioritize client requests, either by the nature of the request or by properties of the client. You minimize the contention on the shared resources (again e.g. malloc) by banging on its synchronization mechanisms with only a few threads instead of hundreds or thousands. There's a lot more detail we could explain that I really don't have time for now. The basic point is that the system schedules threads, but YOU (your code, your server threads) schedule your clients. With thread per client, the system is scheduling your clients based only on the direct and immediate interaction of the threads. (Knowing nothing about the clients, or the server's intent for them.) You can emulate this somewhat in thread-per-client by making all clients wait their turn before making malloc calls, or IO system calls, etc, until your "client scheduler" says it's time (perhaps by signalling a condition variable); but that's far more complicated and messy; and involves a lot more context switches to do the same work. -- Dave Butenhof, David.Butenhof@hp.com HP Utility Pricing software, POSIX thread consultant Manageability Solutions Lab (MSL), Hewlett-Packard Company 110 Spit Brook Road, ZK2/3-Q18, Nashua, NH 03062 .