LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

named locks

Hi all, I need some clarifications about locks in CVI. CmtNewLock creates a lock to be used in multithreaded applications. I am a little puzzled about the first parameter of this function -Lock Name- which according to the online help is:

 

CmtNewLock <script src="launchhelp.js"></script>

lockName const char * The name you want to give to the lock you are creating. Pass NULL if you do not want to name the lock.

Unnamed locks provide better performance than named locks. You must name the lock if you plan to use the lock across multiple processes. The lock name must not be longer than MAX_PATHNAME_LEN characters.

 

An extended search in this board has found little or no specific posts on this parameter. The most relevant is this post by Chris which is somewhat confusing: he says "iit reserves ownership of the thread lock, which is named lock in this case" nevertheless the code included uses NULL as the lock name.


I almost always used unnamed lock in my multithreaded applications (lock name = NULL) but I wonder what the"multiple processes" the online help refers to are?

And what can be the overhead introduced by naming the lock?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 1 of 5
(3,701 Views)

It looks to me like the 'lock' mechanism in CVI is a wrapper for the Mutex object (in Windows). Named Mutex objects allow threads across different processes (not just threads in one process) to synchronise: the name is used to enable the different processes to access the same Mutex object.

 

If the CVI library is super-efficient it may or may not be using the Windows Critical Section object in the case of an unnamed lock, which is a slightly more efficient mechanism than the Windows Mutex for threads within a single process.

--
Martin
Certified CVI Developer
0 Kudos
Message 2 of 5
(3,686 Views)

Roberto,

 

You can use objects like a mutex or shared memory blocks to facilitate inter-process communication for passing data between different applications. It's not an approach I would personally use but it is definitely supported under Windows. The name parameter is how different applications can access those shared objects. Without a name, only the application that creates the object can use it.

 

I hope that helps.

Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 3 of 5
(3,665 Views)

Ok, so till I am dealing with single-process-multiple-threads application I can continue using unnamed locks, with the benefit of a better efficiency.

I'm not planning to run interprocess communication / syncronization so I will stay in this scenario.

 

Thanks all.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,644 Views)

Exactly Roberto.

 

If you aren't going to synchronize to another application, you've got it.

Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 5 of 5
(3,625 Views)