Thread Safe variables - several symbol at link definitions

I'm going through the tutorial "Multithreading in LabWindows/CVI.

The following line is in the tutorial about the variables in Thread-Safe:

"If you need to access the variable in thread-safe from more than one file source, use the macro DeclareThreadSafeScalarVar or DeclareThreadSafeArrayVar in an include (.h) file for create statements for the accessor functions."

OK works with a source file, but when I include the header file in a second file from the source, I have "Several definitions for symbol" errors when link for all functions of accessor in the two source files.

It's probably something simple, but after a few hours I'm at a loss. Any ideas are appreciated.

Scott T

You should have DefineThreadSafeXXX in exactly a source file and a DeclareThreadSafeXXX in any number of source files (or in a file header included in the source files). The following works for me in 2012 of the CVI:

/ * temp.h * /.

#include

DeclareThreadSafeScalarVar (double, Num);

void test (void);

* Temp.c * /.

#include "temp.h".

DefineThreadSafeScalarVar (double, Num,-1);

void main (void) {}

InitializeNum();

test();

}

/ * temp2.c * /.

#include "temp.h".

void test (void) {}

SetNum (1.0);

}

Tags: NI Software

Similar Questions

  • tables dynamic thread-safe

    Hi all

    trying to convert my application single-threaded for multithreading, that I met a new obstacle:

    I would like to have a global data structure. This structure must be dynamically allocated and reallocated as the number of threads (and thus the size of the structure) depends on the program execute / user.

    The main thread as long as secondary threads should be able to access this structure, so I need to use a variable in thread safe, somehow. All the samples I've traveled so far, either use a single variable using the DefineThreadSafeScalarVar macro, or an array of size fixed by using the DefineThreadSafeArrayVar macro.

    I haven't found an example of this type of a dynamic array, unfortunately... Some kind soul would be willing to teach me how to proceed?

    Thank you

    Wolfgang

    In your case, you must use a TSV scalar that contains the pointer is allocated/re-allocated. See the following example of a TSV that mimics a dynamic array of integers. In some cases, a better solution would be to have a TSV scalar that contains a list, say, box tools ListType.

    #include

    DefineThreadSafeVar (int *, DynMem);

    void main (void)
    {
    int * pDynMem, i.;
       
    Initialize the TSV
    InitializeDynMem();
       
    Define HSV 'table' to hold 10 integers
    SetDynMem (malloc (10 * sizeof (int)));
       
    Set and get the 'elements' of TSV
    pDynMem = GetPointerToDynMem();
    for (i = 0; i< 10;="">
    {
    (* pDynMem) [i] = i;
    printf ("DynMem [%d] = %d\n", (* pDynMem) [i], i);
    }
    ReleasePointerToDynMem();
       
    Resize the TSV "array".
    pDynMem = GetPointerToDynMem();
    * pDynMem = realloc (* pDynMem, 20 * sizeof;)
    for (i = 10; I)< 20;="">
    (* pDynMem) [i] = i;
    for (i = 0; i< 20;="">
    printf ("DynMem [%d] = %d\n", (* pDynMem) [i], i);
    ReleasePointerToDynMem();
       
    Free TSV "array".
    pDynMem = GetPointerToDynMem();
    Free(*pDynMem);
    ReleasePointerToDynMem();
       
    Cancel initialization of TSV
    UninitializeDynMem();
    }

  • Common to several symbols mouseover text field

    Hi all.

    I have on stage several symbols and a simple text element.

    I want the element of text to display specific text of each symbol mouseover. E.g. If I mouseover "Symbol_1" text item should display something like "your mouse cursor hovers Symbol_1".

    How is the code for this?

    Thanx.

    PMFR

    Hi, pmfr01-

    You will need to have a mouseover event defined for each symbol instance or an element in a symbol definition.  In the mouseover event, you would update the text field by referring to it in this way:

    sym.getComposition () .getStage ().$("Text1").html ("the cursor of your mouse pointing to mySym1");

    Hope that helps get you started!

    -Elaine

  • Is JTextArea append() method thread-safe?

    It was noted in another ad that in JDK 7, the JTextArea append() method is more explicitly described as being thread-safe:

    http://download.Java.NET/jdk7/docs/API/javax/swing/JTextArea.html#append
    I do not use JDK7, but here is the code for the method append in JDK6_7 (I guess that he has not changed in JDK7?):
    public void append(String str) {
        Document doc = getDocument();
        if (doc != null) {
            try {
                doc.insertString(doc.getLength(), str, null);
            }
            catch (BadLocationException e) {
            }
        }
    }
    As you can see the code simply calls the insertString (...) method of the Document. JDK7 documentation, the insertString (...) method is still marked as being thread-safe:

    http://download.Java.NET/jdk7/docs/API/javax/swing/text/PlainDocument.html#insertString

    I always confused when you work with Threads. A few questions:

    (1) if the append() method eventually calls insertString (...), which is a safe method of thread that does the method append() safe thread?

    (2) assuming that the code in the method append has not changed in JDK 7 documentation has been bad for the first 6 versions of the JDK? Or is the documentation for JDK 7 lack instruction thread safe?

    (3) I know in the past I've suggested append() is thread-safe. It seems I should change my advice to wrap this method in a SwingUtilities.invokeLater (...). Is this a safe approach in any case to avoid confusion?

    camickr wrote:
    The PlainDocument does not use a lock. Here's the code for the JDK6:

    The lock is #insertString AbstractDocument. The additional filter of PlainDocument #insertString code is thread-safe, because it uses only local variables and GetFilter() reading is true or false/null.

    Even if filtering is not done, is it not theoretically possible that change of threads can occur before the super.insertString (...) is running?

    I guess what I'm asking is that if a single line of code runs before the writeLock() method is called is there way for there to be threading issues?

    Yes, but it's similar to the way in which a synchronized map is thread-safe, you can call containsKey (k) followed by get (k), and these methods are "thread-safe", but if you want to combine you need to do an extra lock. The only thread safe object is immutable.
    One difference here is that a card will return NULL but AbstractDocument launches a BadLocationException. Also if you want to get the lock, the only option is to subclass since writeLock() is protected and final.

  • is NamedCache thread-safe?

    Hello

    I use coherance NamedCache (say "TradeCache"), to store objects in the cache.

    My application is designed so that multiple threads can place data in "TradeCache" at the same time.

    What kind of thread safety, we need to take care of?

    Hi user 1696.

    With regard to your questions:

    (a) what kind of locking is used, is that they lock the entire map?
    (b) or basic locking key is made?

    Coherence use essential basic locking.

    (c) if by default all implementations are thread-safe, which is the use of namedcache.lock () api

    NamedCache.lock () is provided so that applications that make use of coherence can have some control over several readers and/or authors using the same object in space of the application. This is not to prevent corruption in the cache store. It must provide a way for applications to control the race as conditions have several operations on the same object at the same time. So that the application can control which of the puts should occur for example.

    Can you please me to any document (short & concise) cohernace good.

    You can find pointers to official documentation and white papers, among others to the OTN on Oracle coherence page following

    http://www.Oracle.com/technology/products/coherence/coherence_suite.html

    and there is also a wealth of information on the site of the Oracle coherence Knowledge Base at:

    http://coherence.Oracle.com

    In regards to your 2nd question about 2 java clients using the same NamedCache and do put and remove operations, you can provide more details on your example? Java clients 2 performing put or remove on the same object or different objects?

    Patrick

    Published by: P Fry on April 30, 2010 12:09

  • Are thread-safe queues

    Hi all

    Are secure i.e. thread queues are enqueue, dequeue Atomic etc?

    I'm looking to use queues to transfer objects between concurrent loops States, but am worried if I need to protect the access via a semaphore.

    Thank you

    Phill

    Yes.  Queue operations are atomic.  It is safe to assume that everything in LabVIEW is thread-safe, unless otherwise stated, it is since always a language designed for operation in parallel.

  • Vs level Variable of Variable severity rule.

    Hello

    I am trying to understand in what situations a Variable of severity level would be used rather than a State Variable. Can someone explain this, as far as I can tell from the documentation that the only practical difference is variable severity of level are only available in the condition as they are defined in.

    See you soon.

    Matt.

    Your interpretation is correct, as seen in the documentation , these variables have different fields of application.

    Rule variables can be referenced in any level of gravity but the level of variable gravity can only be referenced in the expression associated with the level of severity in which are defined variables.

    Keep in mind that we have the variable of register global and available to all objects and types of topology.

    Golan

  • BBM SDK Thread Safe?

    Anyone know if the messages sent/received are thread-safe, or do we do us our own synchronization to ensure that a new message does not come before the end of the old?

    In this case messages would be delivered in the order they are received.  Each call is on the same thread.

  • Does container managed entity manager is thread-safe in stateless session bean?

    Hello

    I have read JEE6 doc and confused with

    Manager managed entity containing does (injected by PersistenceContext annotation) is thread-safe in bean of stateless session in env mutiple-thread?

    See code below, if there are 2 requests to stateless session bean in 2 concurrent threads, is it using the same Instance of the managing body or not?

    @Stateless (name = "HRFacade", mappedName = "HR_FACES_EJB_JPA-HRFacade-HRFacade")

    / public class HRFacadeBean implements HRFacade, HRFacadeLocal {}

    @Resource

    SessionContext sessionContext;

    @PersistenceContext (unitName = "HRFacade")

    Private EntityManager em;

    public places (places sites) persistLocations {}
    EM. Persist (rentals);
    return places;
    }

    public places (places sites) mergeLocations {}
    Return em.merge (rentals);
    }

    {} public void removeLocations (places sites)
    location = em.find (Locations.class, locations.getLocationId ());
    EM. Remove (rentals);
    }

    / * < code > o selection of the places where < code > * /.
    @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED)
    public list < location > getLocationsFindAll() {}
    Return em.createNamedQuery ("Locations.findAll", Locations.class) .getResultList ();
    }

    }

    Yes its safe. Stateless beans would be useless if it wasn't the case. That's the bit of "controlled container" description, as long as you leave the container do its job, you don't have to worry about such details.

  • OTMQ + JCA - it is thread-safe?

    Hello

    Currently, we are conducting a doubt in our minds regarding using the OTMQ with a JCA component. We build into our architecture a component in order to call by a java bean that is deployed inside a WL server, an OTMQ instance that is running on the same machine. This OTMQ instance is the platform independent (not Tuxedo + OTMQ) OTMQ and on the side of Java, we would use a mixture of JCA and, if necessary, JNI calls to establish a connection between these two components.

    My question here is, because WL will have multiple instances of this bean, are there problems I should be aware with respect, using multiple threads in such a component? In my view, that should we not we have no problem with that, given that OTMQ works similar like Tuxedo/q, but I was wondering if there is something you miss here.

    If you could just help me understand if I am having trouble with this architecture, I would be very grateful.

    Thank you

    brunno Attorre

    Hi Brunno,

    The JCA adapter is thread-safe, and if you find any problems associated with the JCA adapter threads, report it to the Support of Oracle.  About OTMQ, in my opinion, that these libraries are thread-safe, you can create an OTMQ multi-threaded server, but we do not support the use of JNI to call one of our libraries.  Why would you use JNI?  You can simply use the JCA/waiting for Message Queuing adapter.

    Kind regards

    Todd little

    Chief Architect of Oracle Tuxedo

  • SimpleParser consistency class is not thread-safe?

    Coherense has the utility class to XML very convinent which we use it a lot in our coherence-related applications.

    But meet us some lock mysterious question (dead end, maybe?) and have identified that it would be that the com.tangosol.run.xml.SimpleParser class is not thread-safe.

    We use tomcat 6 and Spring 2.0.6.

    Application Web has 2 bean that implements the InitializingBean interface.

    Bean A afterPropertiesSet() method will use com.tangosol.run.xml.XmlHelper.loadXml method to parse a XML file.
    Method of Bean B afterPropertiesSet() will acts as a tcp expand clients and retrieve data from a cluster of coherence. Which, I think, consistency will also use XML class useful during parsing of the configuration files.

    We meet randomly blocking of tomcat (which never end starting webapp deployment alternation) as 1 on 2 or 3 tests.

    Use of jconsole and tomcat connection we can see that the main thread stuck in the class SimpleParser. Here's the thread dump.

    Name: main
    State: EXECUTABLE
    Blocked in total: 156 Total expected: 0

    *************************************************************************************************

    Stack trace:
    com.tangosol.run.xml.SimpleParser.instantiateDocument(SimpleParser.java:150)
    com.tangosol.run.xml.SimpleParser.parseXml(SimpleParser.java:115)
    -locking com.tangosol.run.xml.SimpleParser@f10c77
    com.tangosol.run.xml.SimpleParser.parseXml(SimpleParser.java:71)
    com.tangosol.run.xml.SimpleParser.parseXml(SimpleParser.java:84)
    com.tangosol.run.xml.XmlHelper.loadXml(XmlHelper.java:109)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
    org.springframework.beans.factory.support.AbstractBeanFactory$ 1.getObject(AbstractBeanFactory.java:251)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
    -locking java.util.concurrent.ConcurrentHashMap@dee55c
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    -locking java.lang.Object@d21555
    org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
    org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
    org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
    org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
    -locking org.apache.catalina.core.StandardContext@1c64ed8
    org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    -locking java.util.HashMap@76a6d9
    org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:825)
    org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:714)
    org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
    org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    -locking org.apache.catalina.core.StandardHost@1c42c4b
    org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    -locking org.apache.catalina.core.StandardHost@1c42c4b
    org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    -locking org.apache.catalina.core.StandardEngine@37fd24
    org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    org.apache.catalina.core.StandardService.start(StandardService.java:516)
    -locking org.apache.catalina.core.StandardEngine@37fd24
    org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    -locked [Lorg.apache.catalina.Service;@1cc55fb
    org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke (unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke (unknown Source)
    java.lang.reflect.Method.invoke (unknown Source)
    org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    org.apache.catalina.startup.Bootstrap.main (Bootstrap.java:413)

    *************************************************************************************************

    After we have add the tag is based on applying bean B wait on A bean to complete initialization, we encounter is no longer blocked when starting tomcat.

    We suspect that maybe SimpleParser class is not thread-safe and will cause potential deadlock issue.

    Published by: user639604 on June 22, 2009 10:36

    It seems that the 'hand' thread comes to the point that he is responsible for the class of SimpleDocument around the same time as the thread "Timer-0"comes to the point where he is in charge of the class ExternalizableHelper. According to what son get on-demand, if the loading of the class ExternalizableHelper happens point of needing to SimpleDocument after the main thread starts to load SimpleDocument, then a deadlock (inside the JVM loading infrastructure class) happen.

    While you are correct that it is our fault (we shouldn't have used a subset of the ExternalizableHelper static initializer), there is probably a simple solution; Just do the following in an initializer static for your first loads or the classes related to the coherence, for example ClusterConfigurator and OPCacheManager:

    static
      {
      // this should force the ExternalizableHelper class to be loaded
      ExternalizableHelper.makeTrint(0L);
      }
    

    Peace,

    Cameron Purdy | The Oracle coherence

  • Several buttons that links to several pages of a film

    Hi all

    I have an animation flash with 3 buttons, I'm relativley a link to pages on my site, I have a very good job but can't get others to post a link and when I try it makes one that works, works not more...

    Below is the code I use one that works;

    import flash.events.MouseEvent;
    var getIndex:URLRequest = new URLRequest("..) ("/ index.html");

    -Enter button-------.

    E_btn.addEventListener (MouseEvent.CLICK, bclick);

    function bClick(event:MouseEvent):void {}
    navigateToURL (getIndex, "_self");
    }

    Still a bit of a beginner in flash so any help really appreciated.

    Thank you very much

    I see that code for a button there, so I can only guess repeat you the same function several times.  You cannot use the same name for different functions, and you can have the same duplicate function.  Similarly, you cannot declare more than once to the same variable.  You can have buttons share the same function but, and you can assign new values to variables.

    For now, start by creating a unique function for each button definition.

    For further discussion, if your buttons are movieclips you can assign the url to them as variables, or if you name your buttons by using page names they bind to, then the same function could be shared with a few generic tweaks.

  • VARs used in several symbols - help requested

    Hey

    I have a symbol on my scene (let's call it A), there are other symbols (B & C) in A 2. These symbols are interpolated and are moving through one (two not starting at frame one but more later on). B and C are text boxes and both have an actionscript in frame 1. In this script is a certain calculation. For this calculation is a random number generated necessary, however, in the two symbols they should be equal. So somewhere in my little program linking the symbol B and C (or B and C by using A variable or the scene).

    Because of interpolation, things like A.B.myTextbox_txt.text are not possible (or other combinations).

    If you give advice to the use of the classes, please give me a detailed, notice because it's something that I just start learning (and so do not yet use this program which I use for my site). My biggest problem with classes is that I have trouble, manage things like that, addressing the variables, instances, other classes, etc.

    Thanks in advance,

    Barbet

    One approach would be to determine the value and store it in a variable in object for both C & B are sure to have the same value.  Then, every time B and C & come to life they can access that variable using MovieClip (parent) .variableName.

  • Complete a teststand thread safe

    Hello

    I created a vi using the audio wizard and vibrations. He simpply plays a tone of 1 kHz. I start it to use a new thread execution in TestStand (generate the audio wire)

    I then proceed to route the audio from my USE speaker R - the operator must then select the pass/fail if hear sound out of the speaker.

    Then, I continue to send the sound to the speaker L and provide a pass/fail another popup.

    I wonder how I can kill the audio thread 'generate' without including a timeout routine in my vi?

    Not sure if this is possible or safe?

    Thanks & best regards,

    Shane.

    Hey Don1,.

    It seems that this could be an easy fix if I understand your problem. The idea is to have the operator, click go, and then a tone is played on the right side, they confirm / deny hearing it and then it moves on the left side and confirm or deny. The best way to take care of this would be to use only one step for each audio side, for a total if you want, but the idea is to have the LabVIEW to hold the popup of user until the user interacts with it. This could be accomplished with separate vi have by a dialog box pop-up in a while loop when the right audio is running, once the user confirms audio, it stops the loop and returns the result to TestStand. They can then move to the left audio in the same way. If you prefer this in one step, you could use consecutive while loops to hold the user up to the interaction operator dialog box and then move on to the next audio side and then pass the results back as needed.

    Thanks again,

    Nick

  • global variable of symbol change

    Hello world

    I need help, make changes to a global variable.  I created a variable on the creationComplete using the code: sym.setVariable ("information", 1);

    Later in the project, I'd like to call this variable, and then increase the value on a button click. In the button symbol (onClick) I can call the variable using: paragraph var = sym.getComposition () .getStage () .getVariable ('information');

    When I use an alert (paragraph), the correct value appears.  But, on the click, I need to change the value of the variable stageComplete 'information' to 2.

    Can someone give me some pointers on what I'm doing wrong?

    Thank you

    Randy

    Hello

    It seems you want to increment using sym.setVariable () and sym.getVariable ().

    • First step: sym.setVariable("counter",1); This means: counter = 1;
    • Second stage (another sign): sym.setVariable ("counter", sym.getVariable ("counter") + 1); This means: counter = counter + 1; or counter += 1

    Demo: https://app.box.com/s/dqml4wtbcimtjvlkf2ol

Maybe you are looking for

  • Missing command key

    Hello I have a brand new iPad 2 Pro.  I can't find a key on my keyboard, however. Instead, I have an emoji key where the control key should be. I checked my settings, and the keyboard is set to the standard version with the off emoticons. Is it possi

  • P6-2305elm driver for AMD video card

    Hello!I bought the HP Pavilion p6-2305elm with Win 8, I installed Win 7, I can't find the drivers for the video card: AMD Radeon HD 7450, the driver from the official site of AMD do not work!Help me please!Thank you!

  • G50 - sound stops working

    Hi all Could someone help me with a rather strange problem? Sound works fine until what I speak volume to 25%. Less than 25% is working properly, but 26% + put muted its imidiately. I tried to reinstall the sound driver, but no solution. Win 8.1x64 i

  • Assistance needed for the scaling of image 1024 x 1024

    Hi all I did a VI where I load a 1024 x 1024 BMP file. The BMP is generated by an another VI which is to get a picture of a videostream of my webcam. The raster image gets so grayscale for further processing. My final goal is to make a LV facerecogni

  • Best way to initialize a queue with the elements of the array

    Hi guys I'm looking for a bit of performance optimization... I'm developing an application of measure of noise using LV8.6 and Win Xp /Win 7. To say things very simple, I have a loop that samples and a loop that does the calculation. data are shipped