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?

Similar Messages

  • How is it possible to make sure that LV uses the same thread for several threadsafe DLL calls?

    Hello,
    i have a thread safe DLL and most functions are called from serveral threads from the LV apllication without problems.
    In case of an error i have to call an error handler function in this DLL (like WinAPI: GetLastError()) from the same thread which has called the function that failed before.
    I can't use the user interface execution because some functions need a long execution time and i don't want to balk the user interface.
    All other executions than the user interface execution have more than one thread and in most cases the DLL function calls were executed from different threads - so the error handling doesn't work...
    Any idea?
    Thanks for your help!

    Hmmm....
    How about wrapping all of your dll calls in a single VI (or an Action Engine ) and make sure the VI's thread is NOT set for "Same as caller".
    "Threadconfig.vi" (sp?) will also let you dictate the number of threads associated with an execution system. Set your target thread for "1".
    Not sure on the above.
    Please correct me if this is wrong!
    Ben
    Message Edited by Ben on 07-19-2007 08:26 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • 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?

  • How can I use the same thread pool implementation for different tasks?

    Dear java programmers,
    I have written a class which submits Callable tasks to a thread pool while illustrating the progress of the overall procedure in a JFrame with a progress bar and text area. I want to use this class for several applications in which the process and consequently the Callable object varies. I simplified my code and looks like this:
            threadPoolSize = 4;
            String[] chainArray = predock.PrepareDockEnvironment();
            int chainArrayLength = chainArray.length;
            String score = "null";
            ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);
            CompletionService<String> referee = new ExecutorCompletionService<String>(executor);
            for (int i = 0; i < threadPoolSize - 1; i++) {
                System.out.println("Submiting new thread for chain " + chainArray);
    referee.submit(new Parser(chainArray[i]));
    for (int chainIndex = threadPoolSize; chainIndex < chainArrayLength; chainIndex++) {
    try {
    System.out.println("Submiting new thread for chain " + chainArray[chainIndex]);
    referee.submit(new Parser(chainArray[i]));
    score = referee.poll(10, TimeUnit.MINUTES).get();
    System.out.println("The next score is " + score);
    executor.shutdown();
    int index = chainArrayLength - threadPoolSize;
    score = "null";
    while (!executor.isTerminated()) {
    score = referee.poll(10, TimeUnit.MINUTES).get();
    System.out.println("The next score is " + score);
    index++;
    My question is how can I replace Parser object with something changeable, so that I can set it accordingly whenever I call this method to conduct a different task?
    thanks,
    Tom                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    OK lets's start from the beginning with more details. I have that class called ProgressGUI which opens a small window with 2 buttons ("start" and "stop"), a progress bar and a text area. It also implements a thread pool to conducts the analysis of multiple files.
    My main GUI, which is much bigger that the latter, is in a class named GUI. There are 3 types of operations which implement the thread pool, each one encapsulated in a different class (SMAP, Dock, EP). The user can set the necessary parameters and when clicking on a button, opens the ProgressGUI window which depicts the progress of the respective operation at each time step.
    The code I posted is taken from ProgressGui.class and at the moment, in order to conduct one of the supported operations, I replace "new Parser(chainArray)" with either "new SMAP(chainArray[i])", "new Dock(chainArray[i])", "new EP(chainArray[i])". It would be redundant to have exactly the same thread pool implementation (shown in my first post) written 3 different times, when the only thing that needs to be changed is "new Parser(chainArray[i])".
    What I though at first was defining an abstract method named MainOperation and replace "new Parser(chainArray[i])" with:
    new Callable() {
      public void call() {
        MainOperation();
    });For instance when one wants to use SMAP.class, he would initialize MainOperation as:
    public abstract String MainOperation(){
        return new SMAP(chainArray));
    That's the most reasonable explanation I can give, but apparently an abstract method cannot be called anywhere else in the abstract class (ProgressGUI.class in my case).
    Firstly it should be Callable not Runnable.Can you explain why? You are just running a method and ignoring any result or exception. However, it makes little difference.ExecutorCompletionService takes Future objects as input, that's why it should be Callable and not Runnable. The returned value is a score (String).
    Secondly how can I change that runMyNewMethod() on demand, can I do it by defining it as abstract?How do you want to determine which method to run?The user will click on the appropriate button and the GUI will initialize (perhaps implicitly) the body of the abstract method MainOperation accordingly. Don't worry about that, this is not the point.
    Edited by: tevang2 on Dec 28, 2008 7:18 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can I use the same thread to display time in both JPanel & status bar

    Hi everyone!
    I'd like to ask for some assistance regarding the use of threads. I currently have an application that displays the current time, date & day on three separate JLabels on a JPanel by means of a thread class that I created and it's working fine.
    I wonder how would I be able to use the same thread in displaying the current time, date & day in the status bar of my JFrame. I'd like to be able to display the date & time in the JPanel and JFrame synchronously. I am developing my application in Netbeans 4.1 so I was able to add a status bar in just a few clicks and codes.
    I hope somebody would be able to help me on this one. A simple sample code would be greatly appreciated.
    Thanks in advance!

    As you're using Swing, using threads directly just for this kind of purpose would be silly. You might as well use javax.swing.Timer, which has done a lot of the work for you already.
    You would do it something like this...
        ActionListener timerUpdater = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // DateFormat would be better, but this is an example.
                String timeString = new Date().toString();
                statusBar.setText(timeString);
                someOtherLabel.setText(timeString);
        new Timer(1000, timerUpdater).start();That code will update the time once a second. If you aren't going to display seconds, you might as well increase the delay.
    The advantage of using a timer over using an explicit thread, is that multiple Swing timers will share a single thread. This way you don't blow out your thread count. :-)

  • 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

  • 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.

  • Multiple threads but they are using the same thread ID

    I'm a newbie in Java programming. I have the following codes, please take a look and tell me what wrong with my codes: server side written in Java, client side written in C. Please help me out, thanks for your time.
    Here is my problem: why my server program assigns the same thread ID for both threads???
    .Server side: start server program
    .Client side: set auto startup in /etc/rc.local file in a different machine, so whenever this machine boots up, the client program will start automatically.
    ==> here is the result with 2 clients, why they always come up the same thread ID ????????
    Waiting for client ...
    Server thread 1024 running
    Waiting for client ...
    Server thread 1024 running
    But if I do like this, they all work fine:
    .Server side: start server program
    .Client side: telnet or ssh to each machine, start the client program
    ==> here is the result:
    Waiting for client ...
    Server thread 1024 running
    Waiting for client ...
    Server thread 1025 running
    server.java file:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.util.Hashtable;
    import java.util.Enumeration;
    import java.util.regex.Pattern;
    import java.util.Date;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class Server extends Frame implements Runnable
    private ServerThread clients[] = new ServerThread[50];
    private ServerSocket server = null;
    private Thread thread = null;
    private int clientCount = 0;
    //some variables over here
    public Server(int port)
    //GUI stuffs here
    //network stuff
    try
    System.out.println("Binding to port " + port + ", please wait ...");
    server = new ServerSocket(port);
    System.out.println("Server started: " + server);
    start();
    catch(IOException ioe)
    System.out.println("Can not bind to port " + port + ": " + ioe.getMessage());
    public boolean action(Event e, Object arg)
    //do something
    return true;
    public synchronized void handle(int ID, String input)
    //do something
    public synchronized void remove(int ID)
    int pos = findClient(ID);
    if (pos >= 0)
    //remove a client
    ServerThread toTerminate = clients[pos];
    System.out.println("Removing client thread " + ID + " at " + pos);
    if (pos < clientCount-1)
    for (int i = pos+1; i < clientCount; i++)
    clients[i-1] = clients;
    clientCount--;
    try
    {  toTerminate.close(); }
    catch(IOException ioe)
    {  System.out.println("Error closing thread: " + ioe); }
    toTerminate.stop();
    private void addThread(Socket socket)
    if (clientCount < clients.length)
    clients[clientCount] = new ServerThread(this, socket);
    try
    clients[clientCount].open();
    clients[clientCount].start();
    clientCount++;
    catch(IOException ioe)
    System.out.println("Error opening thread: " + ioe);
    else
    System.out.println("Client refused: maximum " + clients.length + " reached.");
    public void run()
    while (thread != null)
    try
    {       System.out.println("Waiting for a client ...");
    addThread(server.accept());
    catch(IOException ioe)
    System.out.println("Server accept error: " + ioe); stop();
    public void start()
    if(thread == null)
    thread = new Thread(this);
    thread.start();
    public void stop()
    if(thread != null)
    thread.stop();
    thread = null;
    private int findClient(int ID)
    for (int i = 0; i < clientCount; i++)
    if (clients[i].getID() == ID)
    return i;
    return -1;
    public static void main(String args[])
    Frame server = new Server(1500);
    server.setSize(650,400);
    server.setLocation(100,100);
    server.setVisible(true);
    ServerThread.java file
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    public class ServerThread extends Thread
    private Server server = null;
    private Socket socket = null;
    private int ID = -1;
    InputStreamReader objInStreamReader = null;
    BufferedReader objInBuffer = null;
    PrintWriter objOutStream = null;
    public ServerThread(Server server, Socket socket)
    super();
    server = _server;
    socket = _socket;
    ID = socket.getPort();
    public void send(String msg)
    objOutStream.write(msg);
    objOutStream.flush();
    public int getID()
    return ID;
    public void run()
    System.out.println("Server thread " + ID + " running");
    while(true)
    try{
    server.handle(ID,objInBuffer.readLine());
    catch(IOException ioe)
    System.out.println(ID + "Error reading: " + ioe.getMessage());
    //remove a thread ID
    server.remove(ID);
    stop();
    public void open() throws IOException
    //---Set up streams---
    objInStreamReader = new InputStreamReader(socket.getInputStream());
    objInBuffer = new BufferedReader(objInStreamReader);
    objOutStream = new PrintWriter(socket.getOutputStream(), true);
    public void close() throws IOException
    if(socket != null) socket.close();
    if(objInStreamReader != null) objInStreamReader.close();
    if(objOutStream !=null) objOutStream.close();
    if(objInBuffer !=null) objInBuffer.close();
    And client.c file
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <netdb.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h> /* close */
    #include <time.h>
    #define SERVER_PORT 1500
    #define MAX_MSG 100
    //global variables
    long lines = 0;
    int sd = 0;
    char command[100];
    time_t t1,t2;
    double timetest = 0.00;
    int main (int argc, char *argv[])
    int rc, i = 0, j = 0;
    struct sockaddr_in localAddr, servAddr;
    struct hostent *h;
    char buf[100];
    FILE *fp;
    h = gethostbyname(argv[1]);
    if(h==NULL) {
    printf("unknown host '%s'\n",argv[1]);
    exit(1);
    servAddr.sin_family = h->h_addrtype;
    memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
    servAddr.sin_port = htons(SERVER_PORT);
    /* create socket */
    sd = socket(AF_INET, SOCK_STREAM, 0);
    if(sd<0) {
    perror("cannot open socket ");
    exit(1);
    /* bind any port number */
    localAddr.sin_family = AF_INET;
    localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    localAddr.sin_port = htons(0);
    rc = bind(sd, (struct sockaddr *) &localAddr, sizeof(localAddr));
    if(rc<0) {
    printf("%s: cannot bind port TCP %u\n",argv[1],SERVER_PORT);
    perror("error ");
    exit(1);
    /* connect to server */
    rc = connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));
    if(rc<0) {
    perror("cannot connect ");
    exit(1);
    //send register message
    rc = send(sd, "register\n", strlen("register\n"), 0);
    //if can't send
    if(rc < 0)
    close(sd);
    exit(1);
    //wait here until get the flag from server
    while(1)
    buf[0] = '\0';
    rc = recv(sd,buf,MAX_MSG-1,0);
    if(rc < 0)
    perror("receive error\n");
    close(sd);
    exit(1);
    buf[rc] = '\0';
    if(strcmp(buf,"autoplay")==0)
    //do something here
    else if(strcmp(buf,"exit")==0)
    printf("exiting now ....\n");
    close(sd);
    exit(1);
    return 0;

    Yes......I do so all the time.

  • I have a new iPad with wifi. When I send messages I can see my sons and my husbands but not my phone number.  We all have an iPad and all use the same apple ID as iPad the bill.  How can I remove their numbers and add mine?

    I have a new iPad with wifi. When I send messages I can see my sons and my husbands but not my phone number.  We all have an iPad and all use the same apple ID as iPad the bill.  How can I remove their numbers and add mine?

    Add another e-mail account to your messages, so people could reach you on that e-mail from messages. As soon as you are online (if you have wifi only iPad) you are able to send and receive messages. i.e. your son can send you a messages from his iPhone addressing it to your (that additional) e-mail address.

  • HT1495 I have just purchased a second ipod and have 2 computers can i use one ipod on each computer with the same account. I have a different playlist on my second computer. Thanks,

    I have just purchased a second ipod and have two computers w7 and xp, can i use one on each computer with the same account. I have a different playlist on my second computer. Thanks.

    Sorry to ask, how do I do it please. I have my first ipod with the same account on both computers that have different libraries one of which I am building now. Do I have to de-authorise my original ipod on the computer that I want to use my new ipod on with the new library and then register my new ipod. I would rather do this than have 2 libraries on one itunes, but keep the same account details. 

  • Hello! I lost my iphone like a month ago, well I reported that phone as lost with my icloud account, now I got a new iphone and I would like to know if I can use that same icloud account with this new phone? The old one will stay reported?

    Hello! I lost my iphone like a month ago, well I reported that phone as lost with my icloud account, now I got a new iphone and I would like to know if I can use that same icloud account with this new phone? The old one will stay reported?

    Thank you.  The old one will stay reported?

  • When I copied my cd collection to my iTunes account, I use the view by CD option in the viewer. How can I get songs from the same album to show nder the same view, instead of making it a separate thing?

    How can i fix this problem with songs from the same album, not being organized under the same  when they are from the same CD?

    Thank you... just read up on iTunes Match.   That stinks, paying a yearly thing... but I understand everyone has to make a dollar.  I think I'm better off just picking the best songs out of my collection storing them on my computer or iPhone then selling my CD's to some used CD place.   If I ever really want to hear a song there are multiple options and if I want it... the .99 to 1.29 option is always there.
    Thank you for the information

  • HT5824 Can use you use the same icloud & itunes account with 2 different cell phone numbers?

    Can I use the same icloud & itunes account with 2 different cell phones that have 2 different numbers?

    Yes. Two iDevices can share the same iTunes Library as long as both are configured to use the same Apple ID.

  • Hello I recently downloaded an app on my iphone 4s - Remote mouse- so i can control my laptop that is connected to my tv, it used to work fine and now the connection fails, I downloaded another app and the same problem occurs, its not the firewall

    Hello I recently downloaded an app on my iphone 4s - Remote mouse- so i can control my laptop that is connected to my tv, it used to work fine and now the connection fails, I downloaded another app and the same problem occurs, its not the firewall and both phone and laptop are conected to the same wifi, i also tried to connect it manually with the ip address and still no connection, can you help??

    Close all open apps by double-tapping the home button, then swiping up and off the screen with the app window (not the smaller icon).
    Then reset: hold down the home button along with the sleep/wake button until you see the apple, then let go.(No data loss) Try it again.

  • Can I use the same USB cable for both the iPhone and the iPad?

    Brnad new user of the iPad - can I use the same USB cable for both the iPhone and the iPad?  The iPad does not charge when plugged into the computer or the wall (110V) adapter.  I've been able to sync in iTunes using the same cable on both.

    Actually, the iPad charger works just fine with iPhones and iPods.  The iPod/iPhone charger will charge an iPad very slowly but no harm will be done.

Maybe you are looking for