Forcing context switching between Labview threads

Hello,
 I have 2 threads interfacing with 2 serial ports on Labview ( Lets say Thread1 , is responsible for polling COM1 and Thread2 for polling COM2 ).
By using occurrences, Thread1 executes before Thread2 and context switching is done according to Labview between the threads. Now, I'm looking to do the following :
As soon as a specific block of code is executed in Thread1, I need Labview to force context switching to execute Thread2. I want to do this in order to synchronize the data received from the 2 threads.
1- So, can this be done, or are there other ways for synchronization ?
2- What if I want Labview to run as a real-time process or a higher priority thread on Windows XP in order to emulate the real-time effect on a Windows XP and not get any delays ? ( I already changed the process priority from the Process explorer, but there seems no effect. I also changed the Labview threads priority to real-time)
3- Are there better approached for (1) & (2) ?  
Thank you,
  Walid F. Abdelfatah 

wfarid wrote:
I already used occurrences for Thread1 to execute before Thread2. Does occurrences guarantee that Labview will switch the context to Thread2, as soon as the context is fired ?
-- Walid 
NO!
LV depends on the OS to schedule threads. If you are sticking with Non-RT then you would be better off getting thread one to do the work while it has teh CPU.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction

Similar Messages

  • Context switching / Threads

    Hello !
    The following program is for 3 Threads which do context switching.
    Often we get '0' zero for the low priority thread when we run this program.
    MY QUESTION IS WHY DO WE GET ZERO ?
    As far as my understanding is concerned; even if preemptive multitasking is done by the threads,
    the low priority thread should have run through few iterations and thus giving some value other
    than zero '0'.
    Secondly most of the time we get negative values for the high priority thread. Why is that ?
    Is it because of the fact that volatile sets the variable 'running' to some different value ?
    The speed of my processor is 1.5GHz.
    GOD BLESS YOU.
    NADEEM.
    // Demonstrates threads priorities.
    class Clicker implements Runnable {
      int click = 0;
      String name ;
      Thread t ;
      private boolean running = true ;
      public Clicker(String tname, int p) {
       name = tname ;
       t = new Thread(this, name);
       t.setPriority(p);
       System.out.println("Current Thread is " + t + " " + t.getPriority());
      public void start() {
       t.start();
      public void run() {
       while (running) {
        click++;
      public void stop() {
       running = false ;
    class HLPriority {
    public static void main(String args[]) {
       System.out.println("Active Count : " + Thread.activeCount());
       Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
       Clicker hi = new Clicker("Hi", Thread.NORM_PRIORITY + 2);
       Clicker lo = new Clicker("Lo", Thread.NORM_PRIORITY - 2);
       System.out.println("Active Count : " + Thread.activeCount());
       lo.start();
       hi.start();
       try {
         System.out.println("Sleeping Thread : " + Thread.currentThread());
         Thread.sleep(10000);
       } catch (InterruptedException e) {
         System.out.println("Main Thread interrupted : " + e);
        hi.stop();
        lo.stop();
       try {
        hi.t.join();
        lo.t.join();
       } catch (InterruptedException e) {
         System.out.println("Interrupted Exception caught : " + e);
       System.out.println("Low priority thread  : " + lo.click);
       System.out.println("Hi  priority thread  : " + hi.click);
    }

    Hello !
    The following program is for 3 Threads which do
    context switching.
    Often we get '0' zero for the low priority thread when
    we run this program.
    MY QUESTION IS WHY DO WE GET ZERO ?Presumably because the low priority thread gets no CPU time.
    >
    As far as my understanding is concerned; even if
    preemptive multitasking is done by the threads,
    the low priority thread should have run through few
    iterations and thus giving some value other
    than zero '0'.You can't make ANY assumptions about when or how much CPU time a given thread will get. Why don't you let your main thread sleep longer--a minute or 5 or ten--and see if LO gets some cycles then.
    Secondly most of the time we get negative values for
    the high priority thread. Why is that ?count = Integer.MAX_VALUE;
    count++; // --> Integer.MIN_VALUE (-2^31)
    I guess 10 seconds is enough time for a thread in a tight loop to count to 2 billion.
    Is it because of the fact that volatile sets the
    variable 'running' to some different value ?Volatile does nothing of the sort, and, in any case, isn't even in your code.
    GOD BLESS YOU.I didn't sneeze.

  • High thread context switching for java web application

    We have been load testing our java web application and observe high cpu usage with 50 users (which doesn't seem practical). The CPU shoots up above 80%. While profiling it with java flight recording (JFR) we see that the context switch rate is 8400 per second (as seen in the Hot threads tab on java mission control). Analyzing the hot threads in jfr, it seems the cpu usage is distributed across the application threads with each thread using less than 3% cpu.
    Increasing the user load to 100, 150 or 200 users we see the cpu shooting up above 90%, the throughput (transactions per second) remaining constant (as seen for 50 users load) while the response time crosses the acceptable threshold values (3 sec). Decreasing the user load to 20 users shows the cpu usage averages out to be above 55%. It certainly isn't true that the application threads are using up the cpu since our application is not a CPU bound application. The Hot Packages tab under Code tab group confirms this by showing that most of the time the application spends in is executing database queries.
    We use glassfish 3.1.2.2 as our application server where the max thread pool is configured to be of 100. Oracle Linux Server release 6.4 is our operating system with linux kernel version as 2.6.39-400.214.4.el6uek.x86_64. I tried executing linux commands namely "watch -n0.5 pidstat -w -I -p " and "watch -n.5 grep ctxt /proc//status" to see the voluntary and involuntary thread context switching at OS level but they don't give any results.
    Suspecting that high context switching could be causing the cpu to shoot up, do you have guidelines on what could be done to confirm that thread context switching is the cause of high cpu and what are there ways to tune the jvm or the application if that's the cause?
    Thanks!

    Kelum -
    We just saw this issue today for the first time. Have you been able to find a cause?
    We upgraded our 32bit Windows operating systems this weekend to use the /3GB flag. Since then, we have seen that our servers have ample heap space, but are dangerously low in PTE memory.
    But when we've been diagnosing the state of the server that produced this error (we run 2 nodes on 3 different computers; only 1 produced this error; the other 5 are working normally), everything looked fine. The server was reporting sufficient PTE availablility, plenty of heap space, and around 172 threads (we expect to be able to run many more than that).
    When we restarted the node, it came up fine and everything appeared to be working normally.
    So I'm looking for any clue as to the root cause, and what kind of resolution to explore. Any clues or pointers would be greatly appreciated.
    Paul Christmann

  • Forced to Close all open applications when switching between users.

    I recently purchased a MacBook Pro 13 inch, and have 2 accounts set up on the computer.
    When switching between users on the computer, I am always forced to close all open applications on the current user, in order to switch to another user.
    I was wondering if there was ANY way to keep the pages (specifically Safari) open when switching to another user, so that I can go back to them when I log back in to the other account.
    thanks for the help!

    Enjoy!
    http://docs.info.apple.com/article.html?path=Mac/10.5/en/8672.html

  • Thread context switching.

    Since I'm working with some real-time applications I'm interested in the thread switching mechanisms of Java ME.
    So my question is when does the context switching take place?
    If a thread A changes the priority of thread B to higher than its own priority will thread B preempt A instantly or is it neccessary to cause the current thread to interrupt?
    How do same priority threads preempt each other?
    What priority is given to the garbage collector?
    Mikael

    Hi Mikael,
    I'm not a ME VM expert, so do not have the deep knowledge. But from what I know:
    - thread switching can take place at any point during execution of java code. That's in interpreted mode. In compiled mode there are some limitations on when it can happen but it still could be described with the words "at almost any point"
    - the scheduler is called to have "fair" policy. That is - all threads get their share of CPU time, the priority defines how big this share is
    - the current thread get preempted when it's exhaused it's currently allocated share of CPU time. next thread is scheduled at that point
    - I don't know whether rescheduling happens when thread priority is modified
    - GC is not a thread and it does not have any priority. It gets invoked according to internal logic which does not depend on logic of the scheduler but rather on heap parameters (configuration and usage)
    Regards,
    Andrey

  • Dynamicall​y-Launched VIs and Context Switching

    I'm working on a project that dynamically calls instances of a reentrant VI, which I assume is a pretty common practice. Everything works pretty well, until the number of calls to this dynamic VI gets pretty large--on the order of 1000 or more--at which point, we begin to see performance degradation. My guess is that we are taking hits due to context switching, since the number of threads far exceeds the number of logical processor cores available.
    A little more background:
    The dynamic VIs being called effectively run as daemons, each running a while loop and waiting on a dedicated input queue to receive data and save it to disk. All are stopped via a globally shared stop notifier (passed as a ControlValue.Set method argument at launch). Each is waiting on its respective queue with a 1 second timeout so that the stop notifier can be polled. Under normal operating conditions, each one will run at some rate between 0.1Hz and 25Hz (the various rates are a large driving factor for separating them and needing to spawn them dynamically).
    So, this leads me to the following questions:
    Am I correct that the context switching is the likely culprit in the performance degradation?
    If so, is there a fundamental difference in how LabVIEW handles multithreading with dynamic VI calls versus explicitly drawing separate while loops on a block diagram, or dropping multiple instances of a reentrant VI directly on the block diagram?
    Is it likely that reducing the number of dynamic clones to equal the number of available processor cores would improve performance? (the scope of each clone would grow, as it would have to maintain the state information that was original distributed across multiple clones)
    I realize that this question is pretty vague without concrete examples, but I'm hoping someone (AQ? Ben? Any of you NI gurus?) out there could provide some general insight into what's going on under the hood without needing to get too specific.

    TurboPhil wrote:
    Each is waiting on its respective queue with a 1 second timeout so that the stop notifier can be polled.
    There is one relatively easy fix you can probably make here - set the timeout to -1 and destroy the queues to stop the loop (destroying the queue will output an error from the wait primitive). This should at least stop all the code from running all the time, although I'm still not sure how the threading of the different VIs will play with each other. This might be an issue if the queue is only created in the VI, but I'm assuming it isn't.
    Try to take over the world!

  • Microphone settings change when switching between a

    Hi all,?After much fun trying to get my mic working with my Xfi Elite Pro i am now having problems with the sound properties changing the settings when i switch between ap
    ps.
    If i sit with the audio properties open and set the mic to the line in 2/mic port it works, then if i fire up skype, msn, guild wars, bf2 or any other app in which i want to use the mic the setting switches back to the "microphone", i then have to minimise the app and force the setting back again.How can i get this setting to be permanently set to line in 2/mic?HELP!!

    Some applications will do this, check out this thread for a little tool that might be of some use to you:
    http://forums.creative.com/creativel...ssage.id=44236
    Cat

  • Context switching.

    Theory: Firewalls essentially partition the Java Card platform’s object system into separate
    protected object spaces called contexts. The
    firewall is the boundary between one context and another. The Java Card RE shall
    allocate and manage a context for each Java API package containing applets1. All
    applet instances within a single Java API package share the same context. There is
    no firewall between individual applet instances within the same package. That is, an
    applet instance can freely access objects belonging to another applet instance that
    resides in the same package.
    That is the theory. What happens in my case. My Java Card project contains three packages and in one there is one Java Card applet. Splitting to three package was necessary because the application is large. What about the object instances from other packages. Are they assigned to other context and what happens when java card applet instance access these objects? Is context switching is happening?

    Patrick,
    Don't worry about context switching. Build a good load test. Run it against
    a "best guess" number of exec threads. Increase the number of threads and
    run again. If overall throughput drops, then decrease the number of threads
    and run again. Start with coarse increments (5 threads?) and work from there
    until you get the best setting.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    http://www.tangosol.com/coherence.jsp
    Tangosol Coherence: Clustered Replicated Cache for Weblogic
    "Patrick Acheson" <[email protected]> wrote in message
    news:3d5aae20$[email protected]..
    >
    In setting the executeThreadCount variable for Weblogic 5.10, if thevariable is
    too high there will be a lot of context switching going on. What wouldconstitute
    a lot of context switching as opposed to what would be a normal orexpected amount?
    Our executeThreadCount is set at 100 and we have 4 CPUs. In Perfmon,about 10%
    of the threads show 1 to 2 context switches per second.

  • 7344 servo motion switching between open and closed loop operation

    I have a custom end-of-line test system presently using a 4-axis 7344 servo controller to perform various functional tests on small, brushed DC motors. The system is programmed in C/C++ and uses flex motion functions to control the motor during testing. Motors are coupled to external encoder feedback and third party PWM drives running in closed-loop torque mode from an analog command signal. The system uses all four motion axis channels on the 7344 board to independently and asynchronously test up to four production motors at a time.
    In closed-loop mode, the system runs without issue, satisfying the battery of testing protocols executed by this system. I now have a request to add additional test functionality to the system. This testing must be run in open loop mode. Specifically, I need to use my +/- 10v analog output command to my torque drive to send different DAC output levels to the connected motor.drive while monitoring response.
    I do not believe the flex motion library or 7344 controller includes functions to easily switch between open and closed loop mode without sending a new drive configuration. I am also under the impression that I cannot reconfigure one (or more) servo controller axis channels without disabling the entire drive. As my system runs each axis channel in an asynchronous manner, any requirement to shutdown all drives each time I change modes is an unworkable solution.
    I am open to all ideas that will allow asynchronous operation of my 4 motor testing stations. If the only solution is to add a second 7344 controller and mechanical relays to switch the drive and motor wiring between two separately configured servo channels, so be it. I just want to explore any available avenue before I place a price tag on this new system requirement.
    Bob

    Jochen,
    Thank you for the quick response. The 7344 board does an excellent job running my manufacturing motor assemblies through a custom end-of-line tester in closed loop mode. A portion of the performance history and test result couples the motor through a mechanical load and external shaft. The shaft is in contact with a linear encoder that closes my servo loop.
    My new manufacturing requirement is to also sample/document how the small DC motor behaves in open loop operation. Your solution is exactly what I need to perform the additional functional tests on the product I am manufacturing. I see no reason why this cannot work. I was originally concerned that I would need to reinitialize the 7344 board after changing axis configuration. Initialization is a global event and impacts all four channels on the 7344 board.
    Using flex_config_axis() to change axis configuration on a single channel without disturbing other potentially running axis channels will solve my concern. It will be several weeks before I can return to the manufacturing facility where the 7344-based testing machine is located. I will update this thread once I verify a successful result.
    Bob

  • Can I have two or more JVMs in one mashin and switch between them?

    Hi all,
    I want to have two JVMs in one mashin and switch between them via a httpListener. If I can, could you please guide me to do it?
    Thanks in advance,
    Orod Semsarzadeh

    may be my question is not fully clear. I mean, I want to have an bottun in my JSP when I click on it, 1 thread will be created and work in another JVM.

  • How to make my applicatio​n programmat​ically switch between English and Russian

    Greetings from Colorado...
    My application needs to be switchable between English and Russian.  Future languages to add are Spanish and Chinese.  The user selects a language
    from a control before starting the program and then the program changes the Captions, Boolean Texts, Graph Labels, and Enum Type Strings to the
    chosen language.  For Russian, this requires a different set of characters.  I have made substantial progress by:
    Control Panels>Region and Language>Keyboards and Languages>Change Keyboards added Russian>Keyboard>Russian on my development
    computer.
    In the LabVIEW.ini file, I added UseUnicode=TRUE (thanks to a suggestion found in this forum)
    Made property nodes for controls and used properties such as Interpret As Unicode (True for Russian, False for English), Text, Font Name, Font Size, etc.
    I have used fonts Arial and Arial CYR for Russian and MS Sans Serif for English
    Set the keyboard for Russian and enter Cyrillic characters into text constants that are set for Arial or Arial CYR font.  Sometimes one works and
    sometimes the other works.  As long as I set the font name in the property node the same way the text went into the text constant, it generally
    works.  I wish I could understand why one works sometimes and the other works other times!
    I have had trouble with the Boolean Text going off-center when changing fonts and languages and it seems that by setting the Lock Text In Center
    property to False and then True again, it seems to work.  Often changing Boolean texts between short and long texts causes some of the long text
    to be non-displayed; I have remedied this by explicitly setting the width of the Boolean text in a property node.
    Often, the Russian text appears as gibberish with strange right-angle characters, :s, =s, and tiny numbers.  I have been able to remedy this on my
    development computer by ensuring that the text constant on the block diagram has the same size as the caption is supposed to have.  This
    is not necessary for normal programming in English, but it seems to help here.  But it doesn't always solve the problem.
    Sometimes the English text appears as Chinese gibberish in an Enum Type selection list or in a graph label.  On my development computer,
    it seems that making the text the last property to change helps here.
    By changing the sequences of assignments to a single property node with a long list of properties, I have been able to make some of these
    controls to switch between languages without gibberish showing up.
    A few hours ago, I had the Russian strings in the Enum Type control working, except that when selecting from the available items, only the first
    word of the Russian string was displayed.  Two of the items start with the same word, so the user can't distinguish them.  
    At that time the English strings were appearing as Chinese gibberish while the list during the selection process displayed in English.  As soon
    as I changed the selection, future attempts to change the selection gave Chinese gibberish during the selection process, too.  But this was only
    a problem in the executable version; the source-code version worked fine.
    In an attempt to get rid of the Chinese gibberish, I made new constants and retyped the items into them.  This worked!  But then, the Russian
    stopped working and gave gibberish angles and tiny numbers, even though I didn't touch any of the code that sets the properties in Russian mode.
    After trying a few sequences of setting the properties for the graph X label on page 2 of my tab control, this label started working correctly for both
    languages.  But the text of that label comes through on page 1 of the tab control, partly obscured by other controls on that page.  After the
    program runs a few more seconds, these shadows disappear.
    Most times I restart LabVIEW, I get an error message saying there was a crash due to fontmgr.cpp, line 7494.  But there actually wasn't a crash.
    My computer has Windows 7 64-bit.  Deployment Computer has Windows 7 32-bit.  LabVIEW version is 8.5.  
    I have probably 50 or 100 more controls and indicators to change to language programmability and figuring out all this stuff for each one is
    terribly time-consuming and there is no assurance that all of them will ever work.  
    At this point, I'm hoping that I am on an entirely wrong path and someone will send me a clue to get me on a path that is more predictable.
    Thanks in advance to all who post ideas!
    Cheers
    Halden 

    Hi All,
    I've made a lot of progress on this translation, but it's been really hard.  There are lots of weird things going on that must be logical because they're in a computer, but I can't figure out what the logic is.  When changing a font on a caption using the front panel, it sometimes changes the font on the caption and sometimes doesn't although the indicator always indicates the new font.  Removing the first character of the unicode font string being sent to the caption seems to help...huh?  Anyway, tabs still can't change language programmatically, and niether can ring controls (some kinds will take the new list of strings, but when selecting, they only display the first word of the string!).  Boolean text can be reprogrammed, but only if the boolean text is set to be the same for both true and false states.  When reprogramming captions on a non-displayed page of a multi-page tab-controlled user interface, the new text appears on the current page until I change pages back and forth.  What a pain!
    Sooo, NI....does LabVIEW 2011 have support for unicode fonts?  Or, is there anything else in the new control style that will support programmatic language changing?
    Halden 

  • Double-tapping to switch between or clear running apps is not working with iPhone 4s.

    when I double tap to close out or switch between running functions, it does nothing ever since yesterday. I have the most current update since last week and the home button works for all other purposes so it's not broken. Now my battery is draining because I cannot shut off running apps. Please help!

    Hi Kate,
    Welcome to Apple Support Communities.
    It sounds like you’re running into a multitasking issue that’s preventing you from switching between apps or forcing them to quit. Try restarting your iPhone, as shown in the article linked below.
    Restart or reset your iPhone, iPad, or iPod touch - Apple Support
    If that doesn’t do it, you can always try restoring the iPhone to factory settings too.
    Use iTunes to restore your iOS device to factory settings - Apple Support
    Cheers,
    -Jason 

  • Problems with project when switched from Labview 8.2.1 to Labview 10

    Hi everyone,
    I recently switched from Labview 8.2.1 to Labview 10.
    Before I can run the project I get the error which you can see in the attachment.
    (The project is running well in Labview 8.2.1)
    I did already check if variables end with a space, but none of them are.
    The variables are also without any slashes, so that couldn't be the problem either.
    Does anybody has any idea what the problem can be, please let me know.
    I hope to hear from some of you soon.
    Regards,
    Kenny
    Attachments:
    Error Labview 10.JPG ‏19 KB

    Your other post in the other thread indicates you've looked at that thread. Based on that have you checked your variable names to see if any of them are multi-line? The error message is basically telling you that you have illegal characters. A carriage return (\r) or a new line (\n) is an illegal character.

  • Dock not working; command-tab switch between programs not working

    The Dock does not work. I have restarted (although the computer will not restart under "Restart", getting stuck at the last part, and needs to be restarted manually). When I change Dock preferences it reverts back to default settings. If I am lucky, the dock will appear and then disappear (poof) without having functioned.
    The command tab function for switching between programs stopped working also.
    The individual programs work, but I have to go to recent items to switch programs.
    Further, I have two Previews open (with different documents in each) even though I have only one Preview program.
    A whole lot of bizarre things that may be connected? I would appreciate any help.

    You could try removing the .plist file again, but this time, try also removing the com.apple.dock.db file. Then log out and log in again.
    Also, it seems as if many people are having similar problems. See [this thread|http://discussions.apple.com/thread.jspa?messageID=9126119].
    So, does the problem persist with another user account?
    If it were my machine, the next thing I'd try is downloading the combo updater from Apple's website and reinstalling it. 10.5.6 is available [here|http://support.apple.com/downloads/MacOS_X_10-5-6_ComboUpdate].

  • Legend behavior when switching between plots in graph.

    I am trying to plot two plots on a single XY graph. The user should be able to switch between the individual plots as well as showing them together. I do not use the Plot.Visible property but instead change Plot.Color to transparent to make sure the Y-scale keeps updating also when the plot is hidden. This works fine, but the Curve in the legend disappears for one of the graphs when it is hidden but not for the other one. I guess that the correct behavior is that they disappear but if it would be possible to make them both visible in the legend the entire time this would be desirable. I have made and attached a simplified VI of what I am trying to accomplish.
    Any ideas about what the problem is and how I could solve it?
    Thanks,
    Johan Gustafsson
    Attachments:
    Prototype_Plot_Switch1.vi ‏31 KB

    Hi,
    i'd changed a little bite your code. Cause if you set the line color to transparent, the legend must also be transparent. So, I think that you can't go that way.
    See my approach.
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Prototype_Plot_Switch1 changedvi.vi ‏24 KB

Maybe you are looking for

  • ICal subscribed calendar on the iPhone

    Hi, I've run on the Mac OS X Server calendar services. What is the URL for the calendar subscription? (not CalDAV account) I want to add Subscribed calendar on the iPhone!  thx for Help SH

  • When I try to purchase an app, I keep getting the (error Id:11200)

    When i try to purchase any app the same error message comes up saying, "There was a problems completing this purchase. Please try again or visit blackberry app world support for more information. (error Id:11200)". And I've tried to visit blackberry

  • Ftp URL, j2re1.3.1 versus j2re1.4.1

    Hello everybody I have a client application running on a PC, OS win2k, which regularly uses an ftp URL to download data files from a remote FTP server. There are two options for this, either through an Ethernet LAN or through slow modem connection (1

  • XI Technical and Business System Definitions For MDM 2.0

    Hi, We're trying to define the XI technical and business system definitions for our MDM 2.0 installation to work with SRM 5.0 and PI 7.0. In the documentation we have we can't find reference to what type of a technical and business system to define.

  • Disable the ability to change ESS who's who data

    I already unchecked the options in IMG Who's who/User's Own data (ESS): Determine Functions. But still the data could be changed in who's who service. Can anyone give me some tip about this? Thanks a lot.