05-04-2010 01:27 PM
I have one thread that is doing TCPIP Aquisition into a Global variable defined in Teststand. And I have another thread that it supose to read it. All are in the same sequence and execution. The problem is that the aquisition thread got a lot of bytes, while the processing thread is reading always only a few. Do you know what the problem could be?
I will attach also some pictures just to be maybe more clear...
05-05-2010 12:37 AM
Hi,
how did you sycronizse the access to the global variable in TestStand ? Are you using a Semaphore ?
Another deal could be using a queue for doing this task.
The read thread will push it a the head and the processing one will pull it from tail.
Hope this helps
juergen
05-05-2010 01:20 AM
I didn't use any semaphores. The idea is that one loop will only write the variable and the other one it will just read it. So there is no problem if I'll read it later. The problem is the teststand string that is not updated or there is a problem with it because I always can read the same amount of byes, while in the write task this global variable is continouslly updated with new data. So it is like a queue in the end, but other design.
I'll try a few more tests because I used previouslly this design and it works. Now there is something that is preventing the variable to be read.
05-05-2010 03:05 AM
That nis a classic case of race condition:
You do not know when the variable is getting updated, therefore you cannot tell wether you are reading old or new data.
Furthermore, i hope that the string is not growing unlimitied, this would be a no-no for certain!
I suggest you to use a queue if you are really interested in a system with single writer/single reader.
Norbert
05-05-2010 05:15 AM
05-05-2010 05:32 AM
I am sure it is not of the case of string handling inside TS
It is as Norbert said: the race condition!
Just try your stuff without using a thread, you will see that it is working.
Another thing you can also use is a notifcation.
So you can communticate/sync between the threads.
Thread A will write the variable when it is finished it sends a notification.
While B wait for the noification. When it comes B can read from variable
Hope this helps
juergen
05-05-2010 05:57 AM
I think your idea is good but I want to say about my case that if you compare the pictures with '_front', you can see that the next character that should be read is '0x00' which means in string life end of an ASCII string. Am I right or not? So this is why I suspect that is a string issue...
The idea of using the string instead of other sync structures is that because my string contains inside timestamps which can help me to identify if I have new data and of course the size of the string which is also a good semaphore for my case. I try to keep it simple.
05-05-2010 06:09 AM - edited 05-05-2010 06:10 AM
But you are not checking for each character to find if it equals to "", you are checking for a string of characters.
regards
Ray Farmer
05-05-2010 06:29 AM
05-05-2010 07:20 AM
I wasn't looking at your Sequence, I was looking at Receive_HDL_Block.JPG. What is that VI doing (the one with number 3 on the icon and Size_in_bytes as an input) ?
Where in teststand are you doing any checking?
I don't really understand your sequence.
You have a sequence (running in a new thread) (why), following by another called Receiver Handler (also running in a new thread) then two more sequences which seem to do some with transmitting something (also running as new threads). You are only waiting on one of these threads (the Receiver Handler). There does seem to be any loops in TestStand, you dont seem to be bothered about the other threads that you have running. What happens when this test sequence finally does stop, what is stopping the Threads that you have running.
Your pictures dont really seem to fit in with your Test Sequence, such as where does Test_005.vi fit into everything
The whole thing is a bit of a nightmare.
Maybe your best bet would be to scrap the lot and start again. Only this time have a better understanding of what you what to achieve, what would be best to put into Teststand and what to put into labview. Whether you really need all those new threads running.
Sorry to be so blunt.
Regards
Ray Farmer