Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Multiple References to the Same CIN in Different VIs

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

When you make a VI reentrant, LabVIEW creates a separate data space for each instance of the VI. If you have a CIN data space in a reentrant VI and you call the VI in seven places, LabVIEW allocates memory to store seven CIN data spaces for the VI. Each of the CIN data spaces contains a unique storage location for the CIN data space for that calling instance.

As with multiple instances of the same CIN, LabVIEW calls the CINInit, CINDispose, and CINAbort routines for each individual CIN data space.

If you have a reentrant VI containing multiple copies of the same code resource, LabVIEW calls the CINInit, CINDispose, and CINAbort routines once for each use of the reentrant VI, multiplied by the number of references to the code resource within that VI.

The following figure shows an example of three VIs referencing a reentrant VI containing one CIN.

By default, CINs written in LabVIEW 5.0 or earlier run in a single thread, the user interface thread. When you change a CIN to be reentrant, that is, to run in multiple threads, more than one execution thread can call the CIN at the same time. Add the following code to your .c file if you want a CIN to run in the current execution thread of the block diagram:

CIN MgErr CINProperties(int32 mode, void *data)

    {

    switch (mode) {

        case kCINIsReentrant:

            *(Bool32 *)data = TRUE;

            return noErr;

            break; }

    return mgNotSupported;

    }

If you read and write a global or static variable, or call a non-reentrant function within your CINs, keep the execution of those CINs in a single thread. Even if a CIN is marked reentrant, the CIN functions other than CINRun are called from the user interface thread. For example, CINInit and CINDispose are never called from two different threads at the same time. CINRun might be running when the user interface thread is calling CINInit, CINAbort, or any of the other functions.

To be reentrant, the CIN must be safe to call CINRun from multiple threads and safe to call any of the other CIN procedures and CINRun at the same time. Other than CINRun, you do not need to protect any of the CIN procedures from each other because calls to them are always in one thread.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit