DaWei's Avatar, Join Date: Dec 2006
Team Leader
Okay, you have the printf function. It is telling you that startdist-self->dist is zero. You don't have to like that, but you have to deal with it. Actually, you are causing it. You make the assignment startdist = self->dist. They are now equal, whatever they are. When you subtract them you will get zero. Right?
brucelee8162's Avatar, Join Date: Aug 2007
Light Poster
that is correct. but that assignment is not made within the while loop, its outside it. And this obviously isnt whats causing it cos I have the same bit of code for going forwards and that works. Any other ideas?
DaWei's Avatar, Join Date: Dec 2006
Team Leader
It IS what's causing it. It's setting it up initially. You are doing NOTHING in the while loop to change the condition.

It is possible that something should be happening outside this code that changes one of those variables. We can't know that, can we? It's YOUR code, it's YOUR system, we see only what you choose to show us. If this outside agent that is supposed to make your code work isn't working, FIX IT.
brucelee8162's Avatar, Join Date: Aug 2007
Light Poster
I've already said that another thread is responsible for updating the self->dist value, so yes you did know that, and I'm posting this because I'm asking for help because I can't fix it, comprende? Here's the thread code:

Code: c
volatile int bStop = false;

void * runMe(void * nouse)
{
   // Do this until we are told to stop
   while (!bStop)
   {
      cr8_delay(15);
      cr8_update();
      pthread_yield();
   }
   
   return NULL;
}
And yes, the above gets called from the main() function. Don't worry I'll ask elsewhere if you dont know.
DaWei's Avatar, Join Date: Dec 2006
Team Leader
You are incorrect. You can tell us that something is happening outside the thread, bet we can't KNOW that something is happening because we aren't at your machine.

If you go back to the code you've shown previously and replace printf("%f\n",(startdist-self->dist)); with printf("%f\n",(self->dist)); and self->dist doesn't change, then you'll know that something is or is not happening outside that function.

There is no mention of self->dist in your other thread's code. Possibly cr8_update is supposed to change self->dist. We cannot know that, we are not at your machine and we can't even see code that you don't bother to show us.

It seems you don't like my attitude, but I'm giving you all the help that I can give remotely, given the paucity of information you supply.

Thread closed.