This isn't necessarily the only way to fix it however just perhaps the most certain to avoid future similar bugs. The database semaphore style suggested
http://galaxylegion.com/forum/viewtopic.php?f=7&t=18651 would also work. Or if the system runs some kind of master thread on the server you could do software semaphores instead of database semaphores like you would in a multi-threaded environment. Just throwing ideas out there to try and help get this taken care of.