[thread] Is Boost suitable for this application?

Hi, all. I don't know anything about Boost, neither OpenMP, pthread nor Windows API thread library. So, before begin learning one of these, I'd like to explain to you how I want my application to work. It deals with running two parallel loops, one in LabView, and the other in C++. It doesn't matter if you don't know anything about LabView, this explanation is easy enough to understand. Attached you can see a picture which shows the desired execution behaviour. I want to know whether my application would be possible to achieve using Boost, or using another API. In another general C++ forum, I was suggested to use Boost. First, the execution begins in LabView. Here, I call a dll function written in C++. This is the "initialization" function. Its aim is to create another thread that will execute the main loop in C++. Then, this "initialization" function ends, because it has to return the control execution to LabView, but the new thread which has just been created must continue executing in its own loop. Now we have two loops in parallel: LabView and C++. In LabView's loop, we call periodically another dll function that has to send and retrieve data from the independent thread in C++. This function, like the other, has to end executing to pass control to LabView again, after it has done its purpose. This will be the behaviour until we call from LabView another dll function to stop the independent thread (not shown in the picture). After this, the LabView program ends. Is it possible to use Boost for this? If so, could you post a brief example about how you'd make it? Thanks in advance, Francisco

Francisco Javier Porras Gálvez
Hi, all. I don't know anything about Boost, neither OpenMP, pthread nor Windows API thread library. So, before begin learning one of these, I'd like to explain to you how I want my application to work. It deals with running two parallel loops, one in LabView, and the other in C++. It doesn't matter if you don't know anything about LabView, this explanation is easy enough to understand. Attached you can see a picture which shows the desired execution behaviour. I want to know whether my application would be possible to achieve using Boost, or using another API. In another general C++ forum, I was suggested to use Boost. First, the execution begins in LabView. Here, I call a dll function written in C++. This is the "initialization" function. Its aim is to create another thread that will execute the main loop in C++. Then, this "initialization" function ends, because it has to return the control execution to LabView, but the new thread which has just been created must continue executing in its own loop. Now we have two loops in parallel: LabView and C++. In LabView's loop, we call periodically another dll function that has to send and retrieve data from the independent thread in C++. This function, like the other, has to end executing to pass control to LabView again, after it has done its purpose. This will be the behaviour until we call from LabView another dll function to stop the independent thread (not shown in the picture). After this, the LabView program ends. Is it possible to use Boost for this? If so, could you post a brief example about how you'd make it? Thanks in advance,Francisco
I did something almost exactly like this about 10 years ago with LabView 7. I made a DLL that created a thread that started a socket listner so that other computers could connect to the embedded Labview to get control data. Now, Labview allows you to create sockets, but the protocol library for the socket data was already in C++ and I tried to create the socket in Labview and pass it into the DLL but I had quite a bit of trouble. It didn't work correctly in Labview 7. I raised a ticket with NI and they basically couldn't help me because none of their help desk knew anything about making your own DLL. Hopefully the support is better now. So anyway, I created a DLL that started a thread and created a socket listner. Then periodically I would call another function in the DLL to deposit control data that the socket listener could send to requestors. I had it start a separate thread because I was using a blocking socket listener. It all works fine. And from Labview's point of view it doesn't matter what library you use to create the socket because all that is hidden in the DLL. I used Visual Studio's C runtime beginthread function and that worked because the embedded Labview system was running on Windows, but of course it isn't portable (neither is pthread or Windows API threads). Boost Threads is portable and would work fine. Do you know what OS your Labview app will be running on? Jerry

----- Original Message -----
From: "Jerry"
Francisco Javier Porras Gálvez
writes: Hi, all.
I don't know anything about Boost, neither OpenMP, pthread nor Windows API thread library. So, before begin learning one of these, I'd like to explain to you how I want my application to work.
It deals with running two parallel loops, one in LabView, and the other in C++. It doesn't matter if you don't know anything about LabView, this explanation is easy enough to understand. Attached you can see a picture which shows the desired execution behaviour. I want to know whether my application would be possible to achieve using Boost, or using another API. In another general C++ forum, I was suggested to use Boost.
First, the execution begins in LabView. Here, I call a dll function written in C++. This is the "initialization" function. Its aim is to create another thread that will execute the main loop in C++. Then, this "initialization" function ends, because it has to return the control execution to LabView, but the new thread which has just been created must continue executing in its own loop.
Now we have two loops in parallel: LabView and C++. In LabView's loop, we call periodically another dll function that has to send and retrieve data from the independent thread in C++. This function, like the other, has to end executing to pass control to LabView again, after it has done its purpose.
This will be the behaviour until we call from LabView another dll function to stop the independent thread (not shown in the picture). After this, the LabView program ends.
Is it possible to use Boost for this? If so, could you post a brief example about how you'd make it?
Thanks in advance,Francisco
I did something almost exactly like this about 10 years ago with LabView 7. I made a DLL that created a thread that started a socket listner so that other computers could connect to the embedded Labview to get control data.
Now, Labview allows you to create sockets, but the protocol library for the socket data was already in C++ and I tried to create the socket in Labview and pass it into the DLL but I had quite a bit of trouble. It didn't work correctly in Labview 7. I raised a ticket with NI and they basically couldn't help me because none of their help desk knew anything about making your own DLL. Hopefully the support is better now.
So anyway, I created a DLL that started a thread and created a socket listner. Then periodically I would call another function in the DLL to deposit control data that the socket listener could send to requestors. I had it start a separate thread because I was using a blocking socket listener.
It all works fine. And from Labview's point of view it doesn't matter what library you use to create the socket because all that is hidden in the DLL. I used Visual Studio's C runtime beginthread function and that worked because the embedded Labview system was running on Windows, but of course it isn't portable (neither is pthread or Windows API threads). Boost Threads is portable and would work fine.
Do you know what OS your Labview app will be running on?
Jerry
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, Jerry. Thanks for your support! I hadn't any idea about what a socket was, but after "googling" a little and read about in NI pages, I have it clearer now. LabView uses a tool called DataSocket to share data between different applications or/and the internet. Moreover, I "discovered" that LabView includes a set of C++ libraries in what is called "Measurement Studio". One of this libraries implements also "DataSocket", and in NI forums they state is possible to share data between two applications in C++ and LabView using this DataSocket tool. So, I think this is the right direction. Your clue was really useful. Thanks, Francisco

Francisco Javier Porras Gálvez
Hi, Jerry.
Thanks for your support!
I hadn't any idea about what a socket was, but after "googling" a little and read about in NI pages, I have it clearer now.
LabView uses a tool called DataSocket to share data between different applications or/and the internet. Moreover, I "discovered" that LabView includes a set of C++ libraries in what is called "Measurement Studio". One of this libraries implements also "DataSocket", and in NI forums they state is possible to share data between two applications in C++ and LabView using this DataSocket tool.
So, I think this is the right direction. Your clue was really useful.
Thanks, Francisco
Sorry for the confusion: Actually I wasn't suggesting that you use a socket to communicate between two applications. Although if you want to be able to run the C++ stuff on a different machine or retrive the data from more than one application then this is a good move. If all you want is Labview to talk to another thread in the same application then use a DLL with a separate thread. There is no reason to make a socket if you can use a DLL instead unless you need to be able to connect to the DLL from more than one app or from an app on a different machine. The only reason I mentioned the socket stuff was as an example of something I needed to run a thread in a DLL to accomplish. I guess I ramble a bit too much :-) Jerry

----- Original Message -----
From: "Jerry"
Francisco Javier Porras Gálvez
writes: Hi, Jerry.
Thanks for your support!
I hadn't any idea about what a socket was, but after "googling" a little and read about in NI pages, I have it clearer now.
LabView uses a tool called DataSocket to share data between different applications or/and the internet. Moreover, I "discovered" that LabView includes a set of C++ libraries in what is called "Measurement Studio". One of this libraries implements also "DataSocket", and in NI forums they state is possible to share data between two applications in C++ and LabView using this DataSocket tool.
So, I think this is the right direction. Your clue was really useful.
Thanks, Francisco
Sorry for the confusion: Actually I wasn't suggesting that you use a socket to communicate between two applications. Although if you want to be able to run the C++ stuff on a different machine or retrive the data from more than one application then this is a good move. If all you want is Labview to talk to another thread in the same application then use a DLL with a separate thread. There is no reason to make a socket if you can use a DLL instead unless you need to be able to connect to the DLL from more than one app or from an app on a different machine.
The only reason I mentioned the socket stuff was as an example of something I needed to run a thread in a DLL to accomplish. I guess I ramble a bit too much :-)
Jerry
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, Jerry. Hehehe, ok, don't worry. I think this "DataSocket" stuff it's going to be very useful for another application I have to deal with. So, in the end, it was very helpful:) So, your suggestion is to use the first aproach, isn't it? This application will run on Windows. In "Cplusplus" forums I was suggested to use Boost because Windows API threads aren't very friendly with synchronization. I don't know much about threads, but what I find more difficult to asume is the fact of creating a thread with a function, and then, after this function has ended, share data with the created thread using another function. Due to this, I can't use OpenMP, for example, because its thread behaviour follows the fork-join model. Anyway, I'll follow your advice and try to integrate your example in my code. Thanks for the attached code! Francisco

I'm pretty good with threads, and what you're describing is rather simple. In fact, it's so simple that I'd suggest using the easiest available function for creating a thread without any need for a big library to wrangle threads. Personally, I have no problem with the Win32 function to create a thread, since it will simply call the single hard-coded entry point. The DLL called by LabView would contain a call to CreateThread (0,0, &entrypoint, 0,0,0); This function returns right away, and meanwhile 'entrypoint' is called on the new thread. To communicate, use a Queue class that has locks to provide for two-threaded access. I think I saw something about "shared" collections in Boost or TR2 or C++0x or something. If that's easy, just use that. Otherwise, since what you want is fairly simple, make a STL queue class (a deque class used in such a way that you always add on one side and remove from the other) and the simplest possible mutex mechanism around the calls so they don't step on each other. Ah, but here's where it gets more complex: if the queue is empty you want the worker thread to sleep not keep spinning idly. Then again, maybe you don't care, and this is indeed very simple: Look for a "Critical Section" or "Mutex" or "Lock" of your choice. The fastest one in the Win32 API is created with InitializeCriticalSection, and looking that up will give you the other calls. To terminate the worker, you send it a command that tells it to stop looping, and it returns from the 'entrypoint' function instead. From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Francisco Javier Porras Gálvez Sent: Sunday, June 06, 2010 12:12 PM To: boost-users@lists.boost.org Subject: [Boost-users] [thread] Is Boost suitable for this application? Hi, all. I don't know anything about Boost, neither OpenMP, pthread nor Windows API thread library. So, before begin learning one of these, I'd like to explain to you how I want my application to work. It deals with running two parallel loops, one in LabView, and the other in C++. It doesn't matter if you don't know anything about LabView, this explanation is easy enough to understand. Attached you can see a picture which shows the desired execution behaviour. I want to know whether my application would be possible to achieve using Boost, or using another API. In another general C++ forum, I was suggested to use Boost. First, the execution begins in LabView. Here, I call a dll function written in C++. This is the "initialization" function. Its aim is to create another thread that will execute the main loop in C++. Then, this "initialization" function ends, because it has to return the control execution to LabView, but the new thread which has just been created must continue executing in its own loop. Now we have two loops in parallel: LabView and C++. In LabView's loop, we call periodically another dll function that has to send and retrieve data from the independent thread in C++. This function, like the other, has to end executing to pass control to LabView again, after it has done its purpose. This will be the behaviour until we call from LabView another dll function to stop the independent thread (not shown in the picture). After this, the LabView program ends. Is it possible to use Boost for this? If so, could you post a brief example about how you'd make it? Thanks in advance, Francisco TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

Some example code, makes use of boost thread, function and bind:
1st - a queue. It accepts "Jobs" which are of type boost::function
participants (4)
-
Francisco Javier Porras Gálvez
-
Jerry
-
John Dlugosz
-
Steve Lorimer