Is this producer-consumer scenario safe about dead-lock?

Hi friends!
I'm developing an application with a producer-consumer scenario. It produces a dead-lock 10% of times approx I execute it . I think the real reason of the crashing resides on the concurrency, because executing only the following code it gets the "main" waiting blocked during its execution after looping the do{...}while(true) sometimes. I've developed this code:
public class CubbyHole
    private int nFinishedThreads;
    private int nTotalThreads;
    public CubbyHole(int TotalThreads)
        this.nTotalThreads = nTotalThreads;
        this.nFinishedThreads = 0;
    public synchronized void put()
        this.nFinishedThreads++;
    public synchronized void get()
        while(nFinishedThreads < nTotalThreads)
            try
                wait();
            catch(InterruptedException ie){}
        notifyAll();
//import java.util.Random;
public class Producer implements Runnable
    private CubbyHole container;
    public Producer(CubbyHole container)
        this.container = container;
    public void run()
        System.out.println(Thread.currentThread().getName() + " has begun");
        try{
            Random rand = new Random();
            Thread.sleep(Math.abs(rand.nextInt()*10));
        catch(InterruptedException ie){}
        System.out.println(Thread.currentThread().getName() + " has finished");
        container.put();
public class Consumer implements Runnable
    private CubbyHole container;
    public Consumer(CubbyHole container)
        this.container = container;      
    public void run()
        System.out.println(Thread.currentThread().getName() + "is waiting for all threads to be finished");
        container.get();
        System.out.println(Thread.currentThread().getName() + "says all threads have finished");
public class Application
    public static void main(String Args[])
        do{
            int nThreads = 2;
            CubbyHole container = new CubbyHole(nThreads);
            Thread[] ProducersArray = new Thread[nThreads];
            for(int i=0; i<nThreads; i++)
                ProducersArray=
new Thread(
new Producer(container));
ProducersArray[i].start();
Thread finalWait = new Thread( new Consumer(container));
finalWait.start();
try
finalWait.join();
catch(InterruptedException ie){}
System.out.println("Application has finished correctly");
while(true);
Please, execute it and give me your results: is the "main" waiting blocked to you?
Is this producer-consumer code safe about dead-lock?
If the answer is no... Why is it waiting blocked?
Thank you in advance.
P.D. I'm spanish, so my english is horrible! I'm sorry!

Thanks ejp:
Moreover, I suppose nothing happens if I write notifyAll() in both methods, put() and get(). In fact this matters only if the producer overwrites the memory space where data is stored, which is not my case.
Is this so?

Similar Messages

  • Best way to handle this producer-consumer situation

    This is, i'm sure a common thing, however, I never really thought about it before. I can't post my VI so a description will have to do. It should go without saying, but I will repeat it's producer-consumer architecture. Let's say you have a signal generator and all the controls for it are in a cluster. A value changes, fires an event in the producer loop and you compare new and old values to determine which button changed. Cool, all good. So then I queue up a read front panel state in my prodcuer loop which is dequeued in my consumer loop. The read front panel state loads all the new values into a cluster which then is fed into a shift register to be accessed from anywhere in my code (see here).
    Now my question is, what should my next state be that I queue up? If I have a single "send commands to sig gen" state, in my consumer loop I again have to determine which value changed in order to know which command to send (because the original determination of what changed was in the producer loop). However, if I have an individual state for each command I want to send, my case structure will get very big, very fast.
    Final option is have one send command state and just write all data on a single control's value change, whether it's new or not (this seems overkill).
    Suggestions please?
    CLA, LabVIEW Versions 2010-2013
    Solved!
    Go to Solution.

    For situations like this I would not send a "state" to the consumer.  I send a "command."   When the consumer receives a command, it determines whether that command is executed immediately or whether it completes the task in process and then handles the new command.
    Along with the command I send a parameter or parameters.  For your signal generator the parameters would probably be something like a cluster of "control ID" and "value."  The control ID would probably be a typedefed enum and the value a DBL.
    What ever you decide, think about it, plan it, and document it before you code it.
    Lynn

  • About Dead Lock on apps tables in 11.5.10.2

    Hi All,
    How to find and Kill dead lock on apps table (11.5.10) ?
    Reg
    Chirag Patel

    Chirag,
    Please refer to the following notes, it should be helpful.
    Note: 109061.1 - How to Check Whether an AOL Table is Locked
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=109061.1
    Note: 223559.1 - Oracle Application Object Library Table Lock Data Collection Test
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=223559.1
    Note: 732271.1 - R12 Oracle Application Object Library (FND): Table Lock Data Collection Test
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=732271.1

  • Chat between multiple users using producer/consumer

    Hi All,
    I'm working on a chat application between multiple users using producer/consumer in flex(pure flex). But i found that this was basically a broadcast service. How do i make sure that i maintain a private chat between any two users using producer/consumer scenario?

    hi,below i write a code,bold lines are properties to use.
    //producer component
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    import mx.messaging.*;
    import mx.messaging.messages.*;
    import mx.messaging.events.*;
    private function sendMessage():void {
    var message:AsyncMessage = new AsyncMessage();
    message.headers = new Array();
    message.headers["prop1"] = 5;
    message.body = input.text;
    producer.send(message);
    ]]>
    </mx:Script>
    <mx:Producer id="producer"
    destination="chat"/>
    <mx:TextInput id="userName"/>
    <mx:TextInput id="input"/>
    <mx:Button label="Send"
    click="sendMessage();"/>
    </mx:Application>
    //consumer component
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="logon();">
    <mx:Script>
    <![CDATA[
    import mx.messaging.*;
    import mx.messaging.messages.*;
    import mx.messaging.events.*;
    private function logon():void {
    consumer.subscribe();
    private function messageHandler(event:MessageEvent):void {
    ta.text += event.message.body + "\n";
    ]]>
    </mx:Script>
    <mx:Consumer id="consumer"
    destination="chat"
    selector="prop1 > 4"
    message="messageHandler(event);"/>
    <mx:TextArea id="ta" width="100%" height="100%"/>
    </mx:Application>

  • First attempt at Producer Consumer Architectu​re: continuous read and dynamicall​y update parameters​.

    Hello,
    I am currently working with two instruments; an Agilent E3646A and an NI 6212 BNC. My objective is to have the 6212 to be continuously taking measurements according to predefined parameters while the E3646A's parameters can be continuously updated. This simple instrument combination is intended to help me learn the necessarry achitecture; continuous measurement, dynamic output control, and more instruments will be added in the future.
    I've previously posted on a similar, but more complicated, setup (http://forums.ni.com/t5/Instrument-Control-GPIB-Se​rial/Split-second-lag-when-controlling-two-instrum​... and was advised to try the Producer Consumer Architecture. I've found relevant literature on the site (http://www.ni.com/white-paper/3023/en/, https://decibel.ni.com/content/docs/DOC-2431), searched the forums and constructed my own VI. While my first attempt at a Producer Consumer Architecture has resolved some of the issues I was having when I first posted on the subject, however, new issues have arisen with regard to reading and stopping the VI.
    I am currently able to run the VI and update the device parameters. Previously, I would get a freeze while the instrument was being updated and could not toggle parameters until it was done. This has been resolved although the read only updates when a parameter has been updated although it is outside of the event structure. Furthermore the Stop button does not work in any context. I've also gotten occasional errors regarding the Deqeue Element but the bulk of the trouble is Error -200279 "Attempted to read samples that are no longer available" at DAQmx Read. I realize that there is a problem in my Producer Loop but haven't been able to figure out how to resolve it.
    This is my first attempt at a Producer Consumer Architecture and already I can see that it is a powerful tool. I read as much as I could and looked at the relevant examples but expected to have some issues in the beginning. Would really appreciate any advice so I can take full advantage of the architecture.
    Hope to hear from you,
    Yusif Nurizade
    Solved!
    Go to Solution.
    Attachments:
    DCe3646A_DAQ6212_Prod_Con_4_13a_2014.vi ‏89 KB

    Jon,
    Thank you for the response and the suggestions.
    I created the Local Variable for the Stop Button and moved the original into its own Event Case. It is now able to stop VI execution although I get Warning -1073676294 which I understand to be the buffer issue. The warning says that this was incurred on VISA Open for the E3646A's Initialize VI which is outside both loops, however, which I don't understand.
    I tried increasing buffer size by decreasing the Number of Samples as per suggestions I found on NI forum threads. I've brought it down as low as 1 but the graph still only updates when an Event occurs and I keep getting the same buffer error. You suggested that the problem could be that they are in the same loop; does this mean that the DAQmx read should be outside both Producer and Consumer Loops or moved into the Consumer Loop? I found a couple of links ( http://forums.ni.com/t5/LabVIEW/Producer-Consumer-​Design-Pattern-DAQmx-Event-Structure/td-p/2744450 ,  http://forums.ni.com/t5/LabVIEW/Producer-Consumer-​Architecture/td-p/494883 -first response) on dealing with an Event Structure that my own VI is based. Alternatively, I found another link ( http://forums.ni.com/t5/LabVIEW/Producer-Consumer-​Design-Pattern-DAQmx-Event-Structure/td-p/2744450 - first response) on a DAQmx Read with an Event Structure that places the graph in the Consumer Loop.
    The core of my purpose in setting up this Producer Consumer Architecture is so that I could read continuously while the instrument parameters are updated dynamically so it's very important that I understand how this works. I am particularly struggling with how the Event Structure is controlling the While Loop's Execution.
    Hope to hear form you,
    Yusif Nurizade
    Attachments:
    DCe3646A_DAQ6212_Prod_Con_4_14a_2014_Edit_I.vi ‏90 KB

  • Insert a DAQ assistant in producer consumer vi

    Hi,
    I am using a DAQ assistant to receive the measurements in the 10 digital ports.
    Hence I use the DAQ assistant icon in the vi s to get these data in to labview.
    Now I require it to convert these digital values from DAQ assistant into analog( this i have done )..
    Thse analog values are to be taken one at a time for further processing.
    I am trying to use this produces consumer loop for it..http://decibel.ni.com/content/docs/DOC-2431
    however i dont know where to fit in the daq assistant .
    Do i still need the DAQ create channel , sample clock etc?
    or do i simply place my daq assistant in the place of the create channelDAQ icon?
    thanks for any help..
     iam completely confused as to what to do with it!!...
    Regards,
    ruser

    Hi,
    Thank you for the suggestions..
    i am sending one vi here..
    this is my basic vi which gets the data from the DAQ and converts it into data ( angular info) we require ie angular position data of lower and upper encoders. This is a continuous real time prcess, which will stop when we press stop in the vi.
    Now i want to take the a set of data (input and output) each, send it to a vi which will receive this set of data; process it and repeat this for the second set of data etc..
    I am also attaching the lvm file . which is the data we are saving now.
    The first attachment is the vi where i am getting the data.
    The second attachment is the lvm data file.
    Thanks.. I would appreciate any help here...
    ruser.
    Attachments:
    absolute encoder.vi ‏805 KB
    LabVIEW Measurement file.docx ‏17 KB

  • Dead Lock what made by another user!(patition table)

    I have a question about Dead-Lock!
    Our Situation is ..
    User "A" made a Patition Table, ACNT_WONJANG
    (without any Trigger,Function, Procedure)
    When "B" - another user - tried to drop its Partition,
    Dead-Lock invoked.
    but A droped it's Partition well.
    What can i Do?
    this is the trace file.
    /oracle/home/admin/ACNT/udump/ora_44478_acnt.trc
    Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.0.0 - Production
    ORACLE_HOME = /oracle/home
    System name: AIX
    Node name: acnt
    Release: 3
    Version: 4
    Machine: 000C962D4C00
    Instance name: ACNT
    Redo thread mounted by this instance: 1
    Oracle process number: 15
    Unix process pid: 44478, image: oracle@acnt (TNS V1-V3)
    *** SESSION ID:(16.394) 2001-10-04 15:00:41.829
    A self-deadlock among DDL and parse locks
    is detected. In most cases, this self-deadlock
    is handled internally.
    This should be reported to Oracle Support
    ONLY IF an error is signalled back to the
    user on a command-line or screen.
    The following information may aid in finding
    user on a command-line or screen.
    The following information may aid in finding
    the problem.
    ORA-04020: deadlock detected while trying to lock object
    F03P.ACNT_WONJANG
    session: 440786b4 request: X
    LIBRARY OBJECT HANDLE: handle=43108348
    name=F03P.ACNT_WONJANG
    hash=76b93583 timestamp=NULL
    namespace=TABL/PRCD/TYPE flags=KGHP/TIM/SML/[02000000]
    kkkk-dddd-llll=0000-0001-0001 lock=S pin=S latch=0
    lwt=43108360[43108360,43108360] ltm=43108368[43108368,43108368]
    pwt=43108378[43108378,43108378] ptm=431083d0[431083d0,431083d0]
    ref=43108350[43108350,43108350] lnd=431083dc[4310824c,425b7ec4]
    LIBRARY OBJECT: object=431080d0
    flags=NEX[0002] pflags= [00] status=VALD load=0
    DATA BLOCKS:
    data# heap pointer status pins change
    0 431082d8 43108154 I/P/A 0 NONE
    HEAP DUMP OF DATA BLOCK 0:
    HEAP DUMP heap name="library cache" desc=0x431082d8
    HEAP DUMP heap name="library cache" desc=0x431082d8
    extent sz=0x224 alt=32767 het=8 rec=9 flg=2 opc=0
    parent=30000030 owner=431080d0 nex=0 xsz=0x0
    EXTENT 0
    Chunk 431080c0 sz= 196 perm "perm "
    alo=196
    431080C0 500000C5 00000000 00000000 000000C4 [P...............]
    431080D0 43108348 431080D4 431080D4 431080DC [C..HC...C...C...]
    431080E0 431080DC 00000000 00000000 00020100 [C...............]
    431080F0 00000000 00000000 00000000 00000000 [................]
    43108100 43108144 00000000 00000000 00000000 [C..D............]
    43108110 00000000 00000000 00000000 00000000 [................]
    Repeat 2 times
    43108140 00000000 431082D8 00000000 43108154 [....C.......C..T]
    43108150 00000000 00000000 00000000 00000000 [................]
    Repeat 1 times
    43108170 00000000 00000000 00000019 00000000 [................]
    43108180 00000000 [....]
    Total heap size = 196
    FREE LISTS:
    Bucket 0 size=0
    Total free space = 0
    UNPINNED RECREATABLE CHUNKS (lru first):
    Total free space = 0
    UNPINNED RECREATABLE CHUNKS (lru first):
    PERMANENT CHUNKS:
    Chunk 431080c0 sz= 196 perm "perm "
    alo=196
    Permanent space = 196

    carlyfromal wrote:
    Here's the thing I myself have an Ipad 3 that I got from Ebay that is activation locked and I have the same issue. Can't get the info. Well,since Apple conveniently decided to discontinue selling the Ipad 3 the only way I could get one was to buy a used one,so it looks to me like they could have some mercy and help a person unlock the thing. We're not dishonest people that go around stealing things,yet because of Apple's brilliant(I use that term sarcastically) idea to put this stupid new crap in place people like us who have to buy second-hand products have to suffer and get screwed out of money we had to save up to buy this stuff! And all anyone can come up with is "well boohoo" or "tough luck" or whatever! But,what about the rights of the rest of us?! Some of you may find this a tad rude, but oh well,tough luck!
    On the other hand, there are those of us that appreciate the theft protection provided by the latest IOS.
    There are certain things to watch out for when purchasing used devices of any sort, the first of which is to ensure that you're not buying stolen property.  Since you are unable to obtain cooperation from the seller, perhaps your device was stolen!

  • If both you and the person you are texting have iMessage, and that person's phone is dead... Will it/Can it still be sent as an imessage? I am getting different answers from people. I want to know if this person was being untruthful about there phone bein

    If both you and the person you are texting have iMessage, and that person's phone is dead... Will it/Can it still be sent as an imessage? I am getting different answers from people. I want to know if this person was being untruthful about there phone being truthful.

    IF that is the only iDevice activated for that recipient, then no. It should not successfully send as an iMessage if the phone is powered off or has no data connection. If you have Send as SMS turned on, it should automatically fallback to SMS after a few minutes. Of course, they won't get this until they power on their phone, assuming they have a text messaging plan with their carrier.

  • How to change the transmissi​on rate of data flow in producer/ consumer pattern

    Hi All
    I am new to labview and trying to design a application to transfer image data in different rates, that means I can change the transfer rate in the transmission process. In fact,I refer to the the Queue Basic.vi to achieve this function by Changing the delay value of dequeue and enqueue.The program is divided into three parts:
    The first part is the sender in vc used to split and send image data.Data size is 226kb and each time we send a 1kb packet;
    The second is labview rate-change part,use producer/ consumer pattern and queue to transfer data;
    The third one is the receiver in vc,receive data in sequence and synthetic images.
    The entire transfer process is: image data was sent from the sender to producer loop through DLL, then enqueue--dequeue in consumer loop--DLL--receiver.The sleep time in vc sender is equal to the delay value in producer loop and this makes it look like the data generated as in the loop.
    Now this is where my dilemma is:
    When transferring data, if the producer loop and consumer loop delay value are equal(both 20ms), I can see image synthesis at a constant speed and no data lose; if I change the consumer loop delay value and make it greater than the producer delay(one is still 20ms and another is 50ms),that means receive in a lower rate and store data in queue. I can see Elements in Queue
    increase but the image data randomly lost, and the image synthesis speed is not reduced.
    My question is why image data loss and I can't see the image synthesis speed reduced when change the delay value in consumer loop?
    Do anyone know how to solve the problem? Are there any examples I can refer to? Any suggestions are greatly appreciated!
    Attachments:
    image1.JPG ‏56 KB

    thisoldman,
    I don't have '/usr/lib/modules/3.17.3-1-ARCH/build/Documentation/VGA-softcursor.txt' on my file system. Does it contain the info about changing the blinking speed?
    P.S. The other two links I found yet before starting this thread. I only found in them the recommendations about changing "the color and shape of the cursor and turning blinking on/off" (as I mentioned in the original question). Did I miss the info about the blinking speed?
    PPS: I found the vga-softcursor.txt here: https://www.kernel.org/doc/Documentatio … cursor.txt
    But that file doesn't tell about changing the blink rate either.
    Last edited by nbd (2014-11-23 20:55:41)

  • Input and output on same device, producer/consumer structure

    Hello interested people,
    I have a question about using the same device for both digital inputs
    and outputs.  I have written a simple program of one while loop
    that continuously polls the device, processes, and requests.  I
    have addressed the device using two DAQmx Asst. and I have attached
    them with their error in/out cluster terminals to provide data flow and
    eliminate the chance of addressing the devices at the same time (which
    produces an error).  Now I want to change this program structure
    to a producer/consumer loop foundation with state machine.  
    In this design, I will have the DI in the producer loop and the DO in
    the consumer loop, under one of the states.  I can't simply
    connect the error in/out ports in this configuration, so my question is
    how to avoid the error caused by addressing the same device
    simultaneously with two different tasks (input and output)?  I
    have attached two VI's, the "One Loop" vi is the original configuration
    (simplified), and the Producer-Consumer vi is a NONSENSICAL program
    that simply represents the desired configuration.  (I don't need
    any comments on the programming of this vi, it is only an example for
    illustration of the problem). 
    I am thinking about bundling the input data and the error cluster, both
    from the PXI 6528 DI, into one cluster, queueing that up, and
    unbundling the de-queued elements for some kind of data flow between
    the producer loop and the "Request" state of the consumer loop. 
    Is this the right approach, or am I barking up the wrong tree?
    Thanks
    Attachments:
    One Loop DO DI.vi ‏102 KB
    Producer-Consumer DI-DO.vi ‏106 KB

    Hello,
    It sounds to me like you really have two modes:
    1. user interface actions determine execution
    2. user interface is locked, and execution is automated.
    I think it would make sense to use the producer consumer for an architecture.  Basically you would do the following:
    1. program the producer to handle the user interface as you normally would.
    2. provide one additional event case in the producer which would be your "automated handling" case.  In that case, you could put a state machine which could run until whatever conditions were met to put your program back in "user interface mode".
    Keep in mind that you can use custom USER EVENTS to programmatically generate events ie. you can trigger the start of your "automated handling" form anywhere in your code at virtually any time.
    I think this would allow you to take advantage of the producer consumer architecture in its intended spirit, while integrating an automated routine.
    I hope this helps!
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • Producer/Consumer Design Pattern with Classes

    I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port.  I thought this would be a good time to start using Classes.  I created a GPIB class which contains member data of:  Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do.  I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware.  This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture. 
    However, in other applications (without classes) I  typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction.  My queue data is a cluster of an "action" enum and a variant to pass data.  Is it OK to use this pattern with classes?  I created a vi and it works fine and attached is a png (of 1 case) of it.
    Are there any problems doing it this way?
    Jason

    JTerosky wrote:
    I'm starting a new project which involves acquiring data from various pieces of equipment using a GPIB port.  I thought this would be a good time to start using Classes.  I created a GPIB class which contains member data of:  Address, Open State, Error; with member vis such as Set Address, Get Address, Open, Close...general actions that all GPIB devices need to do.  I then created a child class for a specific instrument (Agilent N1912 Power Meter for this example) which inherits from the GPIB class but also adds member data such as Channel A power and Channel B power and the associated Member Functions to obtain the data from the hardware.  This went fine and I created a Test vi for verfication utilizing a typical Event Structure architecture. 
    However, in other applications (without classes) I  typically use the Producer/Consumer Design Pattern with Event Structure so that the main loop is not delayed by any hardware interaction.  My queue data is a cluster of an "action" enum and a variant to pass data.  Is it OK to use this pattern with classes?  I created a vi and it works fine and attached is a png (of 1 case) of it.
    Are there any problems doing it this way?
    Including the error cluster as part of the  private data is something I have never seen done and ... well I'll have to think about that one.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Producer Consumer Start Trigger

    Short Explanation: I'm using a 3rd party device to send a TTL signal to use as my start trigger in my VI. My cDAQ and modules appear to have the ability to send a start trigger independantly but I have been unable to hunt down how to do this in a producer/consumer system.  I do have an idea at the bottom of the long explanation.
    Long Explanation:
    I'm running a test system that monitors the pressure wave from a hydrogen/oxygen ignition. Components are a cDAQ-9188 with modules 9222 (x3 high speed AI), 9481 (x2 relay), 9402  (x1 I/O Module), 9221 ("Low" Speed AI). 
    Based upon recommendations in this forum I've placed my DAQ in a producer/consumer architecture. 
    At this point the system mostly works, I still have a few more things to add for all the information I want to collect. However, it records at high speed and the 9221 and the 9222 modules are synchronized. It has successfully collected good data as of this writing.
    When the system starts it will monitor, but not record. I need to fill the test structure with gas to a specific concentration before I ignite/record. When I press the record button I send a TTL signal from the 9402 to my high speed camera and I close a relay on a 9481 which engages a spark system. The spark system takes a variable amount of time to charge and fire so I have a timer that leaves the TTL and the relay active for a half second.
    My problem, and it's a small one, comes in with the monitoring system and the synchronization. In order to get the system to synchronize properly I had to generate an external pulse into PFI0 to use as a trigger. I attempted to assign the various clocks available as a start trigger but I ended up with unsynchronized data.  
    Is there a way to generate a pulse on my 9402 to use as a trigger? It feels silly to me to use an external device when I have something that can generate the signal I need.
    In thinking about this post I might have solved my problem, at least in my head. I'm thinking I can move the TTL output VI (which I will eventually change to DAQmx) into the producer loop and move my true/false statements to the consumer loop as a 1D array within my queue to start the record. Probably more to it than that but I can only learn by experimentation right?
    Thoughts? Recommendations?
    VI attached. 
    Solved!
    Go to Solution.
    Attachments:
    HUCTA Controls.vi ‏186 KB

    You can't generate a pulse with the 9402 itself. The pulse would actually be generated by the 9188. You should create a Counter Output task to generate a pulse train. Try the attached example as a start point to experiment with the counter.
    This Vi is for LabVIEW 2013, if you have an older version let me know and I will try to convert it.
    Camilo V.
    Applications Engineer
    National Instruments
    www.ni.com/support
    Attachments:
    Pulse Train Generator.vi ‏18 KB

  • Producer consumer vs state machine

    Hi there,
    I have been on and around for quite a while to understand how can I re-design an application, which was originally built using a mix of sequence structure, while loops and event structures. And now I am making a newer version of the same application, for research purposes, while learning the LabVIEW techniques. Earlier I used LabVIEW versions 5 and 6 to make simple programs for fuzzy logic and neural networks. And that's not a good reference.
    Ok, after learning that Producer Consumer (PC) and Standard State Machines (SSM or SM) are two new approaches for a better (scalable, flexible and efficient) coding as suggest by veterans, in one thread where I asked about another issue, I have started digging into this topic and now I am on a point where I have to implement it finally (spent pretty much time in the learning phase).
    I have several questions.
    To start the discussion, I would give a brief description of my application.
    It's a networked application, where the network communication happens using DataSocket (one reason to use LabVIEW as the environment).
    We are talking about the client application, which communicates with other applications on remote computer, via Internet.
    User interface involves a tab control, with several pages-
    On startup, the controls/indicators (now onwards referred as controls only), are initialized, datasocket connection is checked (rather internet is checked, and a connection established with the remote datasocket server) (page 1)
    If connected to the datasocket server, the user selects Login/Registration (page 2)
    Login and/or Registration happen on page 3/4
    Then the user sees a table of remote users to connect to (page 5)
    Upon selection of a remote user, and after clicking on "connect", the user will see a video indicator, with a lot of other controls. (page 6)
    On this page with video indicator and controls, the user has a lot of activities, in which many messages are sent and received to/from the remote machine.
    the user may disconnect and go back to page 5, and log out and go back to page 2 and so on.
    I hope this is clear.
    I have thought about two different ways to do this application. Using PS or by SSM.
    In the attachments, I have given a diagram (with errors, of course, because of unlinked controls), for each of the approach, plus the original application's diagram.
    I hope this is sufficient for anybody to understand my case and give suggestions.
    I am looking for suggestions about which is a better model for my type of case. I have been to discussions like this one and saw that there are many issues regarding dequeue in PC model. So I am curious to know if SSM is a better and latest model or it's more primitive? Which looks better for my application's performance?
    Thanks ahead!
    Vaibhav
    Attachments:
    OldDesign.vi ‏41 KB
    PCDesign.vi ‏42 KB
    SSMDesign.vi ‏46 KB

    Vaibhav wrote:
    @ Harold
    Thanks. Any suggestion how can I start and stop that loop in parallel with other loops? Like, if some event occurs, the loop should start execution, and keep on moving, while other events are being traced and executed.
    In those examples where you had a while loop inside a case structure, that bit of code will only execute one time.  It will immediately read the boolean at the start of the program, if the value was true before the porgram started, then the while loop will run.  Once that while loop stops, the case structure will end.  It will never execute again unless you completely stop and restart your program.  If the boolean is false before the program starts, the false case will execute immediately.  Nothing happens since it is empty and it is done, never to run again (unless you stop and restart your VI)  You should turn the structure around.  Put the case structure in the while loop.  Make sure you put a small wait statement in the loop so that it doesn't run full speed eating up CPU cycles just polling the status of the boolean.
    @ Ravens
    Thanks for the detailed comment.
    One thing I would clarify. The user will not be able to switch between the pages using the tab control. The program will direct appropriate page to the user. I kept the tabs visible just for your idea of the pages. Sorry, I didn't mention that.
    Do you think it's still a bad design?
    If the tabs will be hidden or disabled, you will probably be okay.  I wouldn't call it a bad design.  I wouldn't do it that way.  But as long as you understand the possibility of problems and prevent that.  Especially some time down the road when you modify the program in some other way that could lead to a problem because you forgot about the dependencies of the event structures on the state of the state machine. 
    Yes, I agree about only one event structure to handle all the events. But since the user will not be able to click somewhere else, other than those possible controls, I thought to keep it like this.
    I thought the events are captured only if we are in that case. I think I am wrong, right? Events are captured at any time, even if the case has never executed before, or will never execute.  Ok, The events will be captured, but will not be executed until in that case.
    And that's the reason why I have two separate event structures, in two separate phases of the program.
    Because, prior to page 6, the events will occur sequencially. The user will click somewhere, then some message will be transmitted over DataSocket, then some message may come , then again some user action and so on. But, when the user starts using page 6, there will be parallel process of user controls events and actions, and incoming messages and corresponding actions. For this, in the page 6, I need a different kind of execution. So I separated the two event structures.
    At first I thought to have SSM, and then I thought to PC, just because I can have two separate parallel processes - one for user events, and another for messages (because that way I can take maximum advantage of message tracking). But looking at other complexities, I find SSM more appropriate. Can you please tell me how can I have my message loop and events loop parallel to each other and just one event structure?
    You can have a dequeue function in your state machine loop and have it be a consumer loop.  Use a timeout on the Dequeue.  If there is a timeout, have the statemachine execute normally after that perhaps just passing the enum wire straight into the case structure of the state machine.  If it doesn't timeout meaning you got a message, then look at the message that is dequeued and act on it.  Perhaps it means ignoring the enum coming in from the shift register and changing the enum to something else to feed into the case structure of the state machine.  Attached is an example
    Attachments:
    PCDesign[1]_BD.png ‏6 KB

  • Producer Consumer simultaneous operations at different frequencies

    My goal is to do two operations simultaneously.
    The desired end result is:
    1)      Produce an output signal which oscillates at a specified frequency (1 to 10 hz)(using DIO NI-9403). This signal will cause a solenoid to vibrate at different frequencies.
    2)      Monitor voltage on 3 lines in real-time (using analog input NI-9201). This will monitor system response to vibration.
    3)      Produce an output signal which oscillates at a different frequency from (1) – producing 1-second HI values 5 seconds apart. This will cause the system to “pulse”; system response will be monitored.
    4)      Have a front-panel user interface where: the signals in (2) can be monitored; frequency of (1) can be monitored and changed; and the output on (3) can be monitored and changed.
    My efforts so far have been to build a producer-consumer structure. This is my first time using this structure so I may be completely misunderstanding its use. Feel free to correct me if I’m way off target.
    The issue I have is the solenoid in the consumer loop (which handles item (1)) is not operating at the desired frequency. It is too slow. I used a 10ms timer for this loop, but instead it is operating about 1 cycle per second.
    There may be a much better way to approach this, or maybe my program only needs some minor tweaks. Either way, thanks in advance for your help.
    Attachments:
    ProdComsLoop Pulser 2-27-14.vi ‏65 KB

    Hi BradleyDDC,
    It seems from your program that you don't need a producer consumer loop. The only thing you are feeding from one loop to another can be put in one loop, I mean the simulator on button.
    The timer does not determine how fast the loop runs in real time. To get more precise timings, we recommend hardware timed operations as opposed to the software timed ones.
    Instead of using a digital output signal, you can use a counter output task, here is a knowledgebase, which has an example of what you may want.
    Paolo F.
    National Instruments
    Applications Engineer

  • Producer consumer error 200279

    Hello,
    So I’m about to go crazy and hoping someone can help me here. I’m writing a program that controls a motor and using a producer/consumer method to write the data at 10,000 intervals a second. I’ve read through multiple examples and I don’t see what I’m missing. I’m trying to record 18 different readings from a DAQ 9178, 3 readings for voltage module NI 9205, 1 reading for current module Ni 9203, 2 readings for accelerometer module Ni 9234 and 12 readings for temperature module 9213. Every time I run the program I keep getting the error message 200279 and it states that it’s trying to read samples that no longer exist. It advised me to increase the buffer rate. So I did as it suggested in multiple ways and the error messages keeps showing up. I’ve also shut down the computer, exited and restarted Labview several times and none of this worked. I have included the a picture file below.  Where the problem is, is in the producer loop and the error is shown coming out of the DAQ error indicator. One idea I had but I’m unsure how to approach it is to somehow mean the data coming out of the DAQ to reduce what’s getting to the buffer. If anyone knows how to fix this problem please explain it in detail (I mean talk to me like I’m stupid) cause I’ve been stuck on this problem for almost two weeks now. Thank you in advance to anyone who can help.
    SteelTiki  
    Solved!
    Go to Solution.

    The DAQ error isn't related to your choice of architecture, although your implementation of it might be hurting you.  It's almost impossible to follow what's going on in your diagram because you have wires running in many directions (try to keep data flowing from left to right), there are local variables all over the place (almost definitely not needed), and there's a lot of code that's not in the image or is hidden in another frame of the sequence.  Normally one would not have the event structure as the consumer loop (as you've done), and it's generally not a good idea to have multiple event structure in the same VI (with rare exceptions usually involving user events).  It might not solve your problem but it would be worth taking the time to clean up your diagram.  Eliminate sequence structures and local variables as much as possible, move some code into subVIs, and straighten out your wires.
    As for the DAQ error: the DAQ board is reading data into a circular buffer, and you're not reading it fast enough, so samples are being overwritten.  The reason you're not reading it fast enough is because you only read a single sample at a time (the DAQmx Read is configured for 1 sample on multiple channels) but you say you're acquiring 10,000 samples/second.  Since your loop won't run 10,000 times per second, you're not reading all the data, which causes the error.  Try configuring the DAQmx Read for multiple samples.

Maybe you are looking for

  • Trigger Process chain using ABAP code

    Hi All, As per my knowledge there are 2 ways to trigger a process chain using ABAP code : 1) Using FM ‘RSPC_API_CHAIN_START’ and passing process chain name as the parameter 2)Using FM 'BP_EVENT_RAISE' and passing process event as the parameter, which

  • Reporting database creation without purging any data

    We want to create a reporting database where no 'Purge' operation can be performed & all the records will be retained .Production DB & reporting DB are at different geographic location.In this scenario; what tool should be used for replication ? Can

  • I can't install Adobe Flash Player 11.8.800.174

    I get 50% through and get a message to close Internet Explorer and continue. I do so, but the same message appears.

  • Can't make hyperlinks in CS 5

    I can't make hyperlinks in ID CS5. I highlight some text, select new hyperlink in the hyperlink panel, type in a url, cllick ok. The linked text shows up in the panel, but in the document it's still just text. It's not a link. What am I doing wrong?

  • Apple TV 2 w/5.2 software.  AFTER ONE MINUTE IN PAUSE IT GOES BACK TO THE HOME SCREEN.

    I just updated my Apple TV Ser.2 to the 5.2 software.  Now, whenever I pause it it goes back to the ATV home screen after only about a minute.  To resume playing I have cursor down to Netflix, select the program and start playing it again.  Can I jus