About the thread safe variable

Hello,
I have make 2 projects, the first is using to initialize the enviroument an  loading  some modules, and the 2nd using to execute a special work. In the first project, I use the DeclareThreadSafeScalarVar macro to define the handle of a file, I think the file handle can be shared between 2 processes, and each process can access data by the file handle.It is worth mentioning that the 2nd process loading is by the CreateProcess() API. My question is : if the safe variable is initialized in the first process, can I use the safe variable in the second process? Do I need to reinitialize the safe variable in the 2nd process? Thanks.
David

David,
Thread safe variables are only going to work for threads within the same process. Windows does not allow you to access memory outside of the virtual space of your application. Thus the processes act as if they are unaware of each other's data. Even if you send a pointer to the other application, it will not be able to access the data. There are a few other options for interapplication communication.
1. When you are calling CreateProcess() you can pass the new process some command line arguments. If the data you want to send can be serialized, then you can pass it to the other application at start using this command.
2. You can pass the data using WM_COPYDATA which allows you to set up a special structure and send it to the other application. This is similar to what you wanted to do with the thread safe variables, except that this data will be read only and must be sent to the other process using something like SendMessage(). This gets quite a bit more complicated.
3. You can set up a client server architecture and have all of the data management handled by the server process.
From what you have said about your application so far, it may be simpler to just create a single process with two threads. If the applications are dependent on each other, then they likely need to be part of the same process.
National Instruments
Product Support Engineer

Similar Messages

  • If can think the thread safe variable as another lock method

    Hello,
    Assuming that there are two threads, using a thread safe variable as a signal condition. When the 1st thread calling the GetPointerToVarName() to do something, at the "same time", the 2nd thread need to call  GetPointerToVarName() to modify something, I'd like to know if the 2nd thread can continue the work until the 1st thread call the ReleasePointerToVarName()?
    David

    Thread safe variables can only be accessed by one thread at a time, so while the first one is holding the pointer, the second one waits until the pointer is released.
    This is more rigid than using thread locks, in that a thread could call CmtTryToGetLock remaining free to run even if the lock cannot be acquired (supposing running without the locked object makes sense).
    But it is not clear to me from your question whether you actually want thread safe variable functions to lock or are afraid they will do so...
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Can use the same thread safe variable in the different processes?

    Hello,
    Can  use the same thread safe variable in the different processes?  my application has a log file used to record some event, the log file will be accessed by the different process, is there any synchronous method to access the log file with CVI ?
    David

    Limiting concurrent access to shared resources can be better obtained by using locks: once created, the lock can be get by one requester at a time by calling CmtGetLock, the other being blocked in the same call until the lock is free. If you do not want to lock a process you can use CmtTryToGtLock instead.
    Don't forget to discard locks when you have finished using them or at program end.
    Alternatively you can PostDeferredCall a unique function (executed in the main thread) to write the log passing the apprpriate data to it.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Using IPortalComponentProfile: Thread safe variables?

    Hi guys!
    I’m trying to understand (deeply) the framework used by the EP and I found something that disturb me like crazy… the use of the IPortalComponentProfile.
    I just don’t get it The profile suppose to hold variables for your iView instance right? Now, if you are trying to have thread safe variables in your iView  (which is desirable) why you have to used the “application” scope (in a JSP page) to retrieve those variables??? As you know, the application object in a JSP page refers to the ServletContext: All those variables are visible to the entire application which is completely the opposite to the thread safe concept… Am I wrong? Did I miss something?
    If you guys have the clue about this please let me know…
    Thanks in advance!
    Bye.
    Al

    Here's the answer taking from the Portal docs:
    "Except the scope option APPLICATION all the other scope options follow the JSP specifications from Sun Microsystems. <b>The option APPLICATION had to be modified to meet the requirements for a portal.</b> The standard recommendation of APPLICATION would allow access to a the bean through out the whole portal (it would be located in the "Web Application" shell if you look at the following overview chart). In the portal the sphere for APPLICATION is defined as the portal component. This gives the portal component control over the bean but the bean cannot be accessed by other users or other applications of the same user."
    Al.

  • May someone tell me  something about the thread

    The ODP.NET document seems to have little words about the thread,or maybe it is the database who deals with the thread. i have some question aboue it.
    I define a variable in a package specification,
    CREATE OR REPLACE PACKAGE TSTpkg
    is
    counter NUMBER DEFAULT 0;
    END TSTpkg;
    then deal with it in a function
    FUNCTION addc RETURN NUMBER
    AS
    cnt NUMBER:=0;
    BEGIN
    LOOP
    EXIT WHEN admin.tstpkg.counter>100;
    tstpkg.counter:=admin.tstpkg.counter+1;
    cnt:=cnt+1;
    END LOOP;
    RETURN cnt;
    the cnt indicate the number the loop runs,in a single thread program,it will always return 100,for counter is default by 0.Then in C#, i wrote a methord to invoke the funciton"addc" and return the value the function"addc" returns.As far as I am concerned,the variable defined in the package specification should be seen as static element,so if two thread access it, there is just one counter,and the sum of the values return by the two methords invoked in two threads should be 100. But the result is each of the thread returns 100.
    How does the database treat the variable defined in the package specification on the earh?And shouldn't I see it as static one ?
    Who can tell me truth?3ks very much
    (PS: I am Chinese, please forgive me poor engilsh)

    Hi,
    Each database session gets it's own copy of plsql package variables, they're not shared between sessions.
    Cheers
    Greg

  • Confused about static thread safe.help me

    sample codes look like follows:
    public static class test
          public static method1(Object obj)
                //some operations  
    }my question is that is method1 is thread safe?

    Thread safety isn't about methods and it isn't about static. It's about being carefully about access to resources which may be accessed by more than one thread, and in particular may be changed by one thread and accessed by another.
    Local variables are always thread safe, and there's no problem about serveral threads executing the same block of code concurently.
    Thread safety is, in particular, about data items that are linked in some way so that there can be problems if one thread updates one piece of data on the basis of an out of date version of another.
    Databases are, generally, designed to cope with that kind of thing.

  • FIFO Thread Safe Variables

    Hi,
    I am currently trying to develop a Datalogger Application for a Fibre Optic link running at 250Mb/s. I have the code sorted that logs the data, but now have to try and store the data to disk.
    I need 3 Rx threads to keep up with the incoming data to ensure I dont get datalink errors on the card buffer, and I store the data into a Link List for processing by a Write Thread. To do this, I am trying to create a Thread Safe linked list variable as below :
    typedef struct list List;
    struct list {
     int  length;
     Node  *head;
     Node *current;
    DefineThreadSafeVar(List, SafeList);  
    List *SafeListPtr;  
    Then in the main function :
    InitializeSafeList();
    I then have an initialise Linked List function as follows:
    ViUInt32 LL_Initialise(void)
     SafeListPtr = GetPointerToSafeList();
     SafeListPtr = (List*)malloc(sizeof(List));
     SafeListPtr->length = 0;
     SafeListPtr->head = SafeListPtr->current = NULL;
     ReleasePointerToSafeList();
     return 0;
    This appears to initialise the linked list correctly, setting the head and current pointers to NULL.
    But, when i call the following function :
    ViUInt32 LL_GetLength()
     ViUInt32 length;
     SafeListPtr = GetPointerToSafeList();     <- ******************
     length = SafeListPtr->length;
     ReleasePointerToSafeList();
     return (length);
    They line I have marked causes the head and current pointers to return to Uninitialised and then causes a Run Time error when try to use them.
    If you have followed that.....Any ideas?
    Thanks
    Stuart

    Well, I suppose you can create an intermediate buffer in the receiving function:
    create an array of your List structure
    read a record from the queue: if in the correct order, stream it to disk
    if out of order, fill a record of the array
    when you receive the next record in the correct order:
    put it to disk
    sort array content (e.g. with QuickSort passing an appropriate comparison function) and see if and how many records in the buffer can be put to disk
    You may want to design a different algorithm to decide when to sort so that you don't have too much data in the intermediate buffer: sorting on every record may cause too much overhead in your application and a growing buffer of record left to write to disk.
    Please keep posting: this multi-producer-one-consumer framework is an interesting schema to study! ;-)
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Where to read about is-thread-safe tag?

    Hello,
    Does anybody know what tag <is-thread-safe> means and if it mandatory in ias-ejb-jar.xml runtime deployment descriptor. I've found it for helloworld sample for iAS 6.0 SP3 but it is not mentioned in AppServer Programmer's Guide for iAS 6.0 SP2 - the only last guide available on this subject for today.
    Thank you,
    Andrejus

    The SQL plus reference guide immediately springs to mind, as I can see that you are using sqlplus for your output.
    Actually, you don't need any sqlplus formatting. Gicven that you should know that an oracle table_name is never more than 30 characters, just rpad it to 30.
    declare
    cursor c1 is select owner, table_name
    from dba_tables
    where owner = 'SYSTEM'
    group by owner, table_name;
    sql_stmnt varchar2(4000);
    cnt_val number;
    begin
    for c1_rec in c1 loop
    sql_stmnt := 'select count(*) from '||c1_rec.owner||'.'||c1_rec.table_name;
    execute immediate sql_stmnt into cnt_val;
    dbms_output.put_line(rpad(C1_REC.TABLE_NAME,30)||' '||cnt_val||' rows');
    end loop;
    end;Message was edited by:
    Keith Jamieson

  • About the thread pool

    I want to use the thread pool to manage the concurrency in Servlet. Who have some examples about it?And would u pls send it to me?thank u.
    My mail is [email protected]

    may i know ur requirement ?
    u can make servlet method as synchronise so only one client can access that method at a time, this is the simple way...
    let me know ur requirement
    i hope that i can help u .....
    Any more clarifications needed, please inform me.
    [email protected]

  • A question about the Thread class

    the code below are two way of invoke a thread to run:
    A:
    public class Test {
    public static void main(String args[]) {
         Thread myThread = new Thread(){
              public void run(){
                   System.out.println("in myThread! \n");
                   System.out.println(Thread.currentThread());
         Thread th = new Thread(myThread,"new Thread");
         th.start();
    B:
    public class Test {
    public static void main(String args[]) {
         Thread myThread = new Thread(){
              public void run(){
                   System.out.println("in myThread! \n");
                   System.out.println(Thread.currentThread());
         myThread.start();
    i have read many free software's source code, and find many people would like to implement it like A instead of B
    so my question is why A is better than B.
    thanks!!

    A is actually using the constructor which accepts a Runnable. In your case, since you are overriding only run(), you could have simply implemented the Runnable and created the thread th. However, in this model you are using a Runnable you are actually separating the task from the Thread. In B, thread is actually the task which couples them tightly. Therefore, from design point of view, A is recommended with Runnable rather than a Thread unless you have specific reasons to do that.

  • Help!  about the thread and synchronize

    I have worked on this assignment two days but I just can't get the answer it required
    the src code is given below. Have to modify those codez using the semaphore.java which included in the zip to get the output written in test.out.txt(also in the zip)
    http://adri.justmine.org/243.zip
    can anyone help me on this? the assignment is due tommorrow, and I am already mad......

    Sorry about that.
    Here is the src codes
    import java.util.*;
    *************** Hamlet.java **************************
    class Hamlet extends Thread
    public Hamlet() {
    public void run() {
    System.out.println("HAMLET: Armed, say you?");
    System.out.println("HAMLET: From top to toe?");
    System.out.println("HAMLET: If it assume my noble father's person");
    System.out.println(" I'll speak to it, though hell itself should gape");
    System.out.println(" And bid me hold my peace.");
    *****************Marcellus.java******************************
    import java.util.*;
    class Marcellus extends Thread
    public Marcellus() {
    public void run() {
    System.out.println("MARCELLUS: Armed, my lord.");
    System.out.println("MARCELLUS: My lord, from head to foot.");
    ****************Bernardo.java**********************
    import java.util.*;
    class Bernardo extends Thread
    public Bernardo() {
    public void run() {
    System.out.println("BERNARDO: Armed, my lord.");
    System.out.println("BERNARDO: My lord, from head to foot.");
    ***************Semaphore.java*****************************
    public class Semaphore
    public Semaphore(int v) {
         value = v;
    public synchronized void P() {
         while (value <= 0) {
         try {
              wait();
         catch (InterruptedException e) { }
         value--;
    public synchronized void V() {
         ++value;
         notify();
    private int value;
    ***************CurtainUp.java***************
    import java.util.*;
    import Hamlet;
    import Bernardo;
    import Marcellus;
    public class CurtainUp
    public CurtainUp(int hprior, int bprior, int mprior) {
         Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         // Create the actor threads
         Hamlet hamletThread = new Hamlet();
         Bernardo bernardoThread = new Bernardo();
         Marcellus marcellusThread = new Marcellus();
         // Now set the priorities of the actor threads
         hamletThread.setPriority(hprior);
         bernardoThread.setPriority(bprior);
         marcellusThread.setPriority(mprior);
         hamletThread.start();
         bernardoThread.start();
         marcellusThread.start();
    public static void main(String args[]) {
         // Check to make sure that three arguments are passed in for thread
         // priorities, and make sure that the numbers are within the right range.
         // If they are, create an instance of CurtainUp.
         if (args.length == 3) {
         int hprior = Integer.parseInt(args[0]);
         int bprior = Integer.parseInt(args[1]);
         int mprior = Integer.parseInt(args[2]);
         if ((hprior >= Thread.MIN_PRIORITY && hprior <= Thread.MAX_PRIORITY) &&
              (bprior >= Thread.MIN_PRIORITY && bprior <= Thread.MAX_PRIORITY) &&
              (mprior >= Thread.MIN_PRIORITY && mprior <= Thread.MAX_PRIORITY)) {
              CurtainUp curtainUp = new CurtainUp(hprior, bprior, mprior);
         else {
              System.err.println("Range of priorities 1-10 inclusive");
         else {
         System.err.println("useage: Curtainup <priority1> <priority2> <priority3>");
    ********************tThe output *************************
    java CurtainUp N1 N2 N3where N1, N2, N3 are numbers between 1 and 10 inclusive.
    In your program output:
    1. The order in which Bernardo and Marcellus deliver a shared line
    should depend on which actor has higher priority. E.g.
    java CurtainUp 1 1 2HAMLET: Armed, say you?
    MARCELLUS: Armed, my lord.
    BERNARDO: Armed, my lord.
    HAMLET: From top to toe?
    MARCELLUS: My lord, from head to foot.
    BERNARDO: My lord, from head to foot.
    HAMLET: If it assume my noble father's person
    I'll speak to it, though hell itself should gape
    And bid me hold my peace.
    java CurtainUp 1 2 1HAMLET: Armed, say you?
    BERNARDO: Armed, my lord.
    MARCELLUS: Armed, my lord.
    HAMLET: From top to toe?
    BERNARDO: My lord, from head to foot.
    MARCELLUS: My lord, from head to foot.
    HAMLET: If it assume my noble father's person
    I'll speak to it, though hell itself should gape
    And bid me hold my peace.
    2. If Bernardo and Marcellus have equal priority, it doesn't matter
    which one goes first. E.g.
    java CurtainUp 9 1 1HAMLET: Armed, say you?
    MARCELLUS: Armed, my lord.
    BERNARDO: Armed, my lord.
    HAMLET: From top to toe?
    BERNARDO: My lord, from head to foot.
    MARCELLUS: My lord, from head to foot.
    HAMLET: If it assume my noble father's person
    I'll speak to it, though hell itself should gape
    And bid me hold my peace.
    3. Changing the priority of Hamlet in relation to the priorities of
    Bernardo and Marcellus doesn't make any difference to the order in
    which Hamlet speaks his lines. E.g.
    java CurtainUp 9 2 1HAMLET: Armed, say you?
    BERNARDO: Armed, my lord.
    MARCELLUS: Armed, my lord.
    HAMLET: From top to toe?
    BERNARDO: My lord, from head to foot.
    MARCELLUS: My lord, from head to foot.
    HAMLET: If it assume my noble father's person
    I'll speak to it, though hell itself should gape
    And bid me hold my peace.
    java CurtainUp 9 1 2HAMLET: Armed, say you?
    MARCELLUS: Armed, my lord.
    BERNARDO: Armed, my lord.
    HAMLET: From top to toe?
    MARCELLUS: My lord, from head to foot.
    BERNARDO: My lord, from head to foot.
    HAMLET: If it assume my noble father's person
    I'll speak to it, though hell itself should gape
    And bid me hold my peace.

  • About the thread (urgent)

    hi! everyone,
    i have a very urgent problem on thred:
    when run server program, UNIX says:"Exception in thread "main"
    java.lang.NoClassDefDoundError: MonitorThread"!
    plx help!
    thanx very much!!
    what is meaning of that waring message?
    how to deal with it?

    check your classpath:
    currently MonitorThread.class is not in your classpath if you got this message
    marvinrouge

  • What Happened to the thread about problems

    I was getting all sort of emails about the thread:
    "iTunes 7 Little list of Problems (add here yours)" in the Apple Discussions forum "Using iTunes for Mac"
    and now when I try to access it it says I don't have permission...what's going on here APPLE!
    shaun

    I agree with durhamnboy in that I think that a relevant discussion about these bugs is a constructive thing, as long as someone with influence was reading it that is
    Whether this forum is the place to do it is another question - but I instinctively came here first to see what others thought of the new iTunes, so I imagine its the place where most other knowledgable users come. However its Apple's decision as to what is relevant, so there's no point arguing with it I suppose...
    As a software developer myself, I would be happy to see a list of any bugs that we'd missed as a team, especially important in consumer-grade stuff I feel. I'm sure Apple's developers aren't stupid, so will be disappointed to have missed some of these things. Fingers crossed
    MacBook Pro 2.0   Mac OS X (10.4.7)   1GB RAM, 100GB 5400rpm

  • Is Executor thread-safe

    Hello,
    Suppose you have an Executor to execute tasks (one of the standard implementations provided by the JDK).
    Is there any risk if you have multiple threads that use the executor to submit or execute tasks?.
    In other words: Is Executor thread-safe?
    I'm not talking about the working threads that execute the tasks.
    I'm talking about the threads that send the tasks to execution.
    Thank you.

    JoseLuis wrote:
    can you please tell me where can I find that kind of facts, because I could not find it in the javadoc.Well, it isn't a requirement for ExecutorServices, but it how the implementations provided by the java.util.concurrent package operate. That fact is stated in the API for ThreadPoolExecutor in several places:
    In the class description:
    Queuing
        Any BlockingQueue may be used to transfer and hold submitted tasks.Then, all the Constructors that take work queues only take BlockingQueues, and the getQueue() method returns a BlockingQueue.
    Finally, there are only 2 implementations of the ExecutorService provided, ThreadPoolExecutor, and ScheduledThreadPoolExecutor, which subclasses ExecutorService (and does not indicate different rules for Queues).
    >
    if you can tell me about a book or official document it would be great.
    thanx again

  • Newbie: is JSP thread safe?

    New to JSP and trying to understand the thread-safe-code thing.
    An example maybe is the best way to ask (Tomcat 4 and Win2000/IIS, MsSQL2000, MsJDBC)
    I have a mypage.jsp page which uses a bean (mybean.class) to fill up the page from a database and also make updates to the database. So the bean has connect,disconnect,query by returning resultsets, all the database stuff.
    The question: suppose two users get to the page at the same time and press the update button at the same time, what happens?
    user1 -> mypage.jsp -> mybean.class
    user2 -> mypage.jsp -> mybean.class
    So does the mypage.jsp or mybean.class run in tomcat for both users as one copy? Can user1 database update mix up with user2 database update? And if yes, how can i prevent that? Or am I totally lost..
    -- Mixed up newbie --

    Hi,
    What we are talking about here is Transaction not Threading.
    To separate view with business and data access, it's the business class model that take care about it and not the view (JSP pages).
    So here's what to do in a serious world :
    JSP --> class that support JTA (it may be a simple class or an EJB) --> DAO class.
    Hope it's clear enough

Maybe you are looking for

  • How to move an iTunes account

    My situation is that I have several users with their own accounts, each with their own iTunes account and their own iOS devices, on my OS10.6.8 iMac. I would like to move the iTunes accounts and contents to new user accounts on the same computer, and

  • Why did an app that I deleted to redownload it again say that the item no longer exist?

    I had went to the app store to update my apps, and when I did, the blue dots did appear near the icon, but the apps where still in the update selection. Confused, I tried to update them again, but the system said that the item no longer existed in th

  • Where has InDesign CS6 gone and how can I get it back?

    As you know, InDesign CC on Mavericks is a mess atm, so I need to jump back to CS6 while things get better. Thing is, I can't find it, even though my cc app think i have it. So I can't install soemthing that CC thinks is already installed. When I fir

  • Aperture Facebook Uploader: Both Master and Version

    I've searched the forums and see that others had this problem fixed with 3.1.1; but I'm running 3.1.2 and if I edit, crop and otherwise enhance and make a new version and make that version the stack pick, the uploader insists on uploading both (or mu

  • DVD playback problem or exporting problem?

    I recently did a video for a singer to be used on a local video channel. I shot the video on a Panasonic DVX-100P at 24 FPS. I edited the project using Final Cut Pro 5, converted the video using Compressor (to MPEG2) then imported all the contents of