Acquire/Release SpinLocks

Started by
5 comments, last by RWThurman 17 years, 1 month ago
Hi, I'm programming in C++ with 2003 .NET. I'm trying to use the calls _AcquireSpinLock and _ReleaseSpinLock to create a thread safe buffer manager. When I try to include "intrin.h" using "#include <intrin.h>" as suggested on MSND, there's no such include file in my path. "#include <instrin.h> works just fine in 2005 .NET, but I'd rather not upgrade due to other reasons.
Advertisement
#include <intrin.h> is a MSVC 2005.net new feature -- compiler intrinsics.

You can usualy get a similar set of functions from the MS PlatformSDK. I can't find the spinlock functions in 5 minutes of searching, but they are probably in the DDK/SDK.
I've been looking now for 3 hours, and I still can't find it. I can find the kernel one, but nothing for user mode. Maybe they don't exist?
It is possible that it doesn't exist outside of kernel mode.

Which means you might have to write yourself some kernel mode code to get it, which seems silly.

Btw, why aren't you using the traditional mutexes, locks and semaphores to build a thread safe buffer manager?
are you using the free command line toolkit (CLTK) or the full retail version of 2003 (with the IDE and all) ?

Im pretty sure the CLTK is missing all those "extra" includes
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
If you are going to be using spin locks then you should look into using critical sections and the InitializeCriticalSectionAndSpinCount function. You shouldn't stay in a spin lock for very long, but for waits that are extremely short, you can use the above function and EnterCriticalSection to spin for a brief period of time and if it is still unable to aquire the lock, it will wait on the critical section object.

_AcquireSpinLock and _ReleaseSpinLock are new to VS2005 afaik. However intrinsics certainly are not new to VS2005.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Thanks for the good info. After working with the code for a few days, I finally was able to make all the threads interact without any spinlocks or mutexes.

FYI, I was working with a professional version of .NET 2003, and I have professional version of 2005 as well. I was writing a communication system using IO completion ports for a Windows Server 2003 system with duel quadcores (8 cpus). With no locking, this system should really scream.

Thanks again!

This topic is closed to new replies.

Advertisement