This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: spinlock class?


On Mon, Apr 28, 2003 at 04:24:36PM -0400, Joe Buehler wrote:
>Christopher Faylor wrote:
>
>>You mean critical sections, maybe?  Although cygwin uses "spinlocks" in
>>one or two cases, they are only for edge cases that should be hit rarely.
>>They're basically a 'if (!test) Sleep (0)'.
>
>OK.  Here's what I ended up doing:
>
>	void lock() {
>		while (InterlockedExchange (&the_lock, 1)) {
>			low_priority_sleep (0);
>		}
>	}
>
>	void unlock() {
>		InterlockedExchange (&the_lock, 0);
>	}

But why not just use a critical section?  It's roughly the same thing,
isn't it?

cgf


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]