Lock a session before you acquire and use its instrument API handle when you want to prevent another thread or process from simultaneously using the same instrument handle. Use the following methods to implement session locking:

  • InstrSession.GetLockState
  • InstrSession.LockSession
  • InstrSession.UnlockSession
  • InstrSessionMgr.GetUniqueKeyName

Session locking is effective only when all components that access the session use the locking functions properly. Locking a session blocks other threads or processes that lock the session before they use it. Locking a session in one component cannot prevent another component that fails to call the locking functions from caching the instrument handle and using the instrument API on that handle. In this way, a session lock is like an operating system critical section or mutex you use to control access to a shared resource.

Unlike an operating system mutex, however, the thread that calls the InstrSession.LockSession method does not own the lock. Instead, the key string you pass to the method owns the lock. Pass the Thread ID or Process ID as the key string to lock on a per-thread or per-process basis. Pass a string that uniquely identifies the object that owns the lock, such as TestFixture1, to lock on an object basis. Pass a key string that you obtain by calling the InstrSessionMgr.GetUniqueKeyName method to lock on an absolute basis.

If you call the InstrSession.LockSession method on a session that is already locked with a different key, the calling thread sleeps until you acquire the lock or until the timeout period you specify expires.