Geeks With Blogs
Chris Breisch   .NET Data Practices
Search this Blog!

Implementing critical sections is a problem we all stumble across from time-to-time.  I recently was trying to do one in SQL, and discovered that it was harder than I expected.  I didn't think of this method, which is a good one, by Louis Davidson.  He uses Application Locks (sp_getapplock, sp_releaseapplock) to solve the problem, which does exactly what you need, of course.

Usually critical sections are fairly easy to implement, but also must be handled carefully.  You must make sure that a) nothing can bypass your critical sections checks, and b) you always release your locks (or whatever necessary to notify waiters that you've left your critical section).  This method accomplishes the second, and warns you that you must handle most of the first issues yourself.

Still, even with that caveat, it's worth a look.


Posted on Thursday, May 24, 2007 2:52 PM Database Practices | Back to top

Comments on this post: Using Application Locks to Implement a Critical Section in T-SQL Code

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Chris J. Breisch | Powered by: