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?


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);
	}
--
Joe Buehler


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