Sign in to follow this  
RWThurman

Acquire/Release SpinLocks

Recommended Posts

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.

Share this post


Link to post
Share on other sites
#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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this