Subj : Re: Optimization to Jeffrey Richter's COptex (Windows)? To : comp.programming.threads From : Luke Elliott Date : Wed Jan 26 2005 11:22 pm Joseph Seigh wrote: > On Wed, 26 Jan 2005 22:12:14 GMT, Luke Elliott > wrote: > >> >> Also I noticed in there they use a lock, inc pair instead of lock, xadd >> that the optex code will use (as a result of InterlockedIncrement), so >> I'm going to try that and will report back if there's any noticeable >> performance improvement. >> > > inc sets condition flags. You need an algorithm that works with that. > COptex > doesn't since it need to know of the result == 1 or is > 1. Also xadd > is only > on 486(?) or later processors so your limited on which machines it can > run on. > CriticalSection goes way back. They probably haven't updated it. inc is > slightlly faster than xadd but not enough that I use that a factor in > design > decisions. > > No measurable difference AFAICT. The only real difference between the crit sec and optex algorithms is the lockCount is -1 when not owned in CS and 0 in optex. I assume Richter did that to take advantage of the os zeroing the shared portion to avoid needing another "initialized" flag to cope with races between creator and opener. .