LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Ivi_LockSession

The documentation suggests that the use of Ivi_LockSession/UnlockSession within the driver code results in a thread-safe driver, however, experimentation leads me to believe that this is not quite the full story.

I found that IviLockSession/UnlockSession did not protect the enclosed code from multiple threads on different sessions.  That is, if my driver is used to open two sessions on two different instruments, a thread on one session does not respect the lock of the other session.

The fact that the Ivi_LockSession function requires a ViSession parameter suggests very strongly that the lock is only applicable to that session.  A thread on a different session will not be blocked and so, in such cases, further care has to be taken to ensure that such threads do not cause any problems.  I found I had to use a CriticalSection in order to protect my code in this multi-session scenario.

Have I correctly understood the behaviour of Ivi_LockSession?  Is the lock only applicable to threads on the same session?



Alan Hume, Pickering Interfaces Ltd


0 Kudos
Message 1 of 2
(3,098 Views)
Hi Alan,

I have been having a look into this, and it seems your findings are seemingly accurate. It is also worth remembering to 'balance' every LockSession call with a corresponding UnlockSession call - although I am fairly sure it wouldn't cause the behaviour you have seen.

Regards,

Dan - NIUK
0 Kudos
Message 2 of 2
(3,028 Views)