Example Code

Protecting File Access With Semaphores using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

 Overview
This example VI shows how to protect a file from being manipulated by more than one application.

 
Description
There is no built in functionality to protect LabVIEW config files, or files in general,  from being opened and manipulated by more than one application at a time. Attached is an example of how to protect a config file open with semaphores. The VI creates a semaphore named as the file path to preserve this file from double manipulation.  You can run multiple instances of this VI to see the functionality.

 
Requirements

  • LabVIEW 2012 (or compatible)

 
Steps to Implement or Execute Code

  1. Run the VI
  2. Select or create a new file
  3. Try to launch another VI istance for the same File

 

Additional Information or References
VI Block Diagram

 Protecting Config File Access With Semaphores LV2012 NI verified.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Stephen B

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Todd S.
NI Employee (retired)
on

Well done, sir.  Tell your brother that you are way cooler.  Way.

Todd S.
LabVIEW Community Manager
National Instruments