Subj : Re: Lock Free -- where to start To : comp.programming.threads From : Joe Seigh Date : Thu Sep 29 2005 06:00 pm David Schwartz wrote: > "Joe Seigh" wrote in message > news:QradnVuGiqT2o6HeRVn-og@comcast.com... > > >>So you're saying lock based solutions will scale better then lock-free >>ones? > > > It depends upon which of the dozens of possible meanings of "scale" you > intend. In general, if by "scale" you mean show improved real world > performance as load, in general, increases, then yes, lock-based solutions > will scale better than lock-free ones. > > Consider a case where you have four threads. Threads A and B want to > access the same collection and threads C and D want to access the same > collection. With only a single CPU, both a lock-free and lock-based solution > will run one thread at a time and it will run at full speed. > > Now, let's scale this to two CPUs. The lock-based solution will never > run thread A and B at the same time. It will always run one of A/B and one > of C/D. The scaling is perfect and the performance doubles since contending > threads never run. > > The lock-free solution will randomly match threads. Whenever it happens > to schedule A and B or C and D at the same time, each thread will run at > some small fraction of its maximum as the FSB bounces the shared/modified > data back and forth. > > Granted this is an extreme example, but the point is that contention is > bad and lock free algorithms tend to maximize contention. > What happens when you scale to 4 cpu's? -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .