<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Thread locks in LabWindows in LabWindows/CVI</title>
    <link>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/726480#M36282</link>
    <description>Hi Chris_G, thanks for your clear explanation. That answers my question.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 17 Jun 2008 17:11:05 GMT</pubDate>
    <dc:creator>coanda</dc:creator>
    <dc:date>2008-06-17T17:11:05Z</dc:date>
    <item>
      <title>Thread locks in LabWindows</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/725686#M36245</link>
      <description>&lt;P&gt;&lt;FONT face="Arial"&gt;At the site: &lt;A href="https://www.ni.com/en/support/documentation/supplemental/06/multithreading-in-labwindows--cvi.html" target="_blank" rel="noopener"&gt;https://www.ni.com/en/support/documentation/supplemental/06/multithreading-in-labwindows--cvi.html&lt;/A&gt; regarding multi-threaded application development there is the following code snippet:&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt;-----&lt;BR /&gt;&lt;BR /&gt;int lock;&lt;BR /&gt;int count;&lt;BR /&gt;&lt;BR /&gt;int main (int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; int functionId;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtNewLock (NULL, 0, &amp;amp;lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction, NULL, &amp;amp;functionId);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtGetLock (lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; count++;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtReleaseLock (lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE, functionId, 0);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtDiscardLock (lock);&lt;BR /&gt;}&lt;BR /&gt;int CVICALLBACK ThreadFunction (void *functionData)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtGetLock(lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; count++;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtReleaseLock(lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;----&lt;/FONT&gt; &lt;TT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/TT&gt;&lt;FONT face="Arial"&gt;But I'm having a hard time understanding how &lt;FONT face="Comic Sans MS"&gt;count &lt;/FONT&gt;is at all related to &lt;FONT face="Courier New"&gt;lock&lt;/FONT&gt;. What if I have multiple global variables that need to be locked in different threads, how is this handled?&lt;/FONT&gt;&lt;TT&gt;&lt;BR /&gt;&lt;/TT&gt;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 23 Oct 2025 20:44:40 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/725686#M36245</guid>
      <dc:creator>coanda</dc:creator>
      <dc:date>2025-10-23T20:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Thread locks in LabWindows</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/726467#M36281</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;P class="MsoNormal" style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face="Calibri" color="#000000"&gt;Hello coanda,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="Calibri"&gt;Thanks for posting on the NI forums.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Let me start by saying that you’re quite right.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;CmtGetLock() does not put a lock on any variable, but instead it reserves ownership of the thread lock, which is named &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;lock &lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-family: 'Courier New'"&gt;&lt;FONT face="Calibri"&gt;in this case.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;An attempt to take ownership of the thread lock from a separate thread must wait until the owning thread releases the lock using CmtReleaseLock().&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In other words, if thread 1 reaches the CmtGetLock() function before thread 2 does, then thread 2 suspends execution until thread 1 reaches CmtReleaseLock().&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Once the lock is release by the first thread, the second thread can then reserve ownership of the lock, and continue execution.&lt;NAMESPACE prefix="o" ns="urn:schemas-microsoft-com:office:office"&gt;&lt;/NAMESPACE&gt;&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN style="mso-bidi-font-family: 'Courier New'"&gt;&lt;FONT face="Calibri"&gt;So, if you desire to protect multiple global variables in different threads, you must only modify these variables when ownership of a lock is activated.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It is up to the developer to coordinate which lock is reserved when accessing a certain variable.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The important thing to understand is that there is never any lock put on a variable, rather ownership of locks themselves are reserved and released.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If we wanted to protect another global variable in the example from the above post named &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'"&gt;count2&lt;/SPAN&gt;&lt;SPAN style="mso-bidi-font-family: 'Courier New'"&gt;&lt;FONT face="Calibri"&gt;, then the modified code would look like the following:&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color="#000000"&gt;-----&lt;BR /&gt;&lt;BR /&gt;int lock;&lt;BR /&gt;int count;&lt;BR /&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: yellow; mso-highlight: yellow"&gt;int count2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;BR /&gt;int main (int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; int functionId;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtNewLock (NULL, 0, &amp;amp;lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadFunction, NULL, &amp;amp;functionId);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtGetLock (lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; count++;&lt;BR /&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: yellow; mso-highlight: yellow"&gt;&lt;STRONG&gt;count2++&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtReleaseLock (lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE, functionId, 0);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtDiscardLock (lock);&lt;BR /&gt;}&lt;BR /&gt;int CVICALLBACK ThreadFunction (void *functionData)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; CmtGetLock(lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; count++;&lt;BR /&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: yellow; mso-highlight: yellow"&gt;count2++;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; CmtReleaseLock(lock);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;-----&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color="#000000"&gt;&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2008 16:57:10 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/726467#M36281</guid>
      <dc:creator>Chris_G.</dc:creator>
      <dc:date>2008-06-17T16:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Thread locks in LabWindows</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/726480#M36282</link>
      <description>Hi Chris_G, thanks for your clear explanation. That answers my question.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Jun 2008 17:11:05 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/726480#M36282</guid>
      <dc:creator>coanda</dc:creator>
      <dc:date>2008-06-17T17:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Thread locks in LabWindows</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/727299#M36300</link>
      <description>How is &lt;SPAN class="noindex"&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="Calibri"&gt;CmtGetLock()/CmtReleaseLock() different form windows SDK EnterCriticalSection()/LeaveCriticalSection()?&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;Are they wrapper functions around them to provide a way for the Linux runtime to do the Linux equivalent?&amp;nbsp; &lt;BR /&gt;If not, why should I use the Cmt functions instead of the SDK functions I'm used to?&lt;BR /&gt;&lt;BR /&gt;As an aside, my externally visible Email has been changed, how do I update my forum profile?&amp;nbsp; I could see what it was set to with the forum MyProfile, but couldn't find a place to update it.&lt;BR /&gt;&lt;BR /&gt;--wally.&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 18 Jun 2008 16:17:11 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/727299#M36300</guid>
      <dc:creator>wally_666</dc:creator>
      <dc:date>2008-06-18T16:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Thread locks in LabWindows</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/728452#M36332</link>
      <description>&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;FONT face="Calibri" color="#000000"&gt;Hello wally_666,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0in 0in 10pt;" data-unlink="true"&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="Calibri"&gt;Thank you for your questions as well.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Functionally speaking, CmtGetLock() and CmtReleaseLock() are no different than the Windows SDK EnterCriticalSection() and LeaveCriticalSection() functions.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;When calling Windows SDK functions from LabWindows/CVI, one must include the proper header files and libraries in order to access the Windows SDK functions. Using the CmtGetLock() and CmtReleaseLock() functions from LabWindows/CVI eliminates this step, and also reduces compile time.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;For more information on calling Windows SDK functions from LabWindows/CVI, see the following link:&amp;nbsp; Using the Windows SDK in LabWindows/CVI&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0in 0in 10pt;" data-unlink="true"&gt;&lt;FONT face="Calibri" color="#000000"&gt;As far as using the functions during runtime on a Linux machine, the LabWindows/CVI Run-Time Module for Linux&amp;nbsp;supports these two functions, and therefore can be executed on a Linux machine.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0in 0in 10pt;"&gt;&lt;FONT face="Calibri" color="#000000"&gt;Lastly, to update the current email address in your NI User Profile, follow these steps:&lt;/FONT&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo1;"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;FONT face="Calibri"&gt;(1)&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Calibri"&gt;&lt;STRONG style="mso-bidi-font-weight: normal;"&gt;Log in&lt;/STRONG&gt; to your profile&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo1;"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;FONT face="Calibri"&gt;(2)&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Calibri"&gt;At the top of a discussion forum thread, click on the &lt;STRONG style="mso-bidi-font-weight: normal;"&gt;My Profile&lt;/STRONG&gt; link, located just under the thread category (e.g. “LabWindows/CVI”)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo1;"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;FONT face="Calibri"&gt;(3)&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Calibri"&gt;On the &lt;STRONG style="mso-bidi-font-weight: normal;"&gt;Personal Profile&lt;/STRONG&gt; tab of your NI User Profile, click on the &lt;STRONG style="mso-bidi-font-weight: normal;"&gt;Modify your NI User Profile&lt;/STRONG&gt; link at the top of the tab.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="MsoListParagraphCxSpMiddle" style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo1;"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;FONT face="Calibri"&gt;(4)&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Calibri"&gt;Once the &lt;STRONG style="mso-bidi-font-weight: normal;"&gt;My Profile&lt;/STRONG&gt; page pops up, click on the &lt;STRONG style="mso-bidi-font-weight: normal;"&gt;Modify Profile&lt;/STRONG&gt; link, which is the third link down on the page.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="MsoListParagraphCxSpLast" style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; mso-list: l0 level1 lfo1;"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;FONT face="Calibri"&gt;(5)&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Calibri"&gt;On the &lt;STRONG style="mso-bidi-font-weight: normal;"&gt;Modify Profile &lt;/STRONG&gt;page, you can change your email address in the textbox under the &lt;STRONG style="mso-bidi-font-weight: normal;"&gt;Enter your email address:&lt;/STRONG&gt; heading.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Oct 2025 20:45:24 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/728452#M36332</guid>
      <dc:creator>Chris_G.</dc:creator>
      <dc:date>2025-10-23T20:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Thread locks in LabWindows</title>
      <link>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/730663#M36395</link>
      <description>Chris_G,&lt;BR /&gt;&lt;BR /&gt;Thanks for the instructions on editing my profile, somehow I couldn't get to that page when I tried last week.&lt;BR /&gt;&lt;BR /&gt;Saving compile time is no big deal for me and I've been mixing CVI and SDK code since the beginning (CVI 3) but I'll be using the Cmt routines in my next project as it'll save me learning about mixing Windows and Linux thread locking semantics, neatly solving the problem I'll face.&lt;BR /&gt;&lt;BR /&gt;--wally.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 24 Jun 2008 14:02:09 GMT</pubDate>
      <guid>https://ni.lithium.com/t5/LabWindows-CVI/Thread-locks-in-LabWindows/m-p/730663#M36395</guid>
      <dc:creator>wally_666</dc:creator>
      <dc:date>2008-06-24T14:02:09Z</dc:date>
    </item>
  </channel>
</rss>

