2025r1 Linux x86_64 Cooperative threading. I’m getting an IllegalLockingException for trying to unlock a CriticalSection on the wrong thread. However, the code is very simple and there’s no possible way for this to be wrong.
I use a module named ObjectLocks
that gets inited on app open with its own lock and dictionary. I call ObjectLocks.GetLock(Id) to fetch a CriticalSection from the dictionary. Then lock it, do some work, and unlock it. The GetLock function uses its own lock to make sure the dictionary isn’t touched by another thread while doing its job.
The trouble is, there’s simply no way for the locking exception to happen. My code looks like this:
Var Lock As CriticalSection = ObjectLocks.GetLock(Id)
Lock.Enter
Try
// Do something, Lock is not touched inside the routine
Catch Err As RuntimeException
// Report the error
End Try
Lock.Leave
That’s it. There’s nothing at all complicated about this usage. There’s no other code outside the Try/Catch but between the Enter/Leave, so no possibility of an exception aborting before the CriticalSection can be unlocked. No other code in the project uses the ObjectLocks module. And yet it sometimes fires the IllegalLockingException. Does anybody have any idea how this could possibly happen? Because I’m reaching the conclusion that this is a framework bug, which of course I’ll never be able to reproduce.
20 posts - 5 participants