I took out the &'s and the code compiled. Now I'm having some difficulty with the threads in my code. I have three threads that I want to run simultaneously. They essentially listen to three different serial ports. The problem is the first thread loops far faster (more often?) than the other two for some reason. Is there a way I can easily synchronize the three threads so that they execute the same fast? Without wasting cpu time?
Here is the code. I added the printfs so I could see what was going on.
Code:
void *serial_thread_1()
{
for(;;)
{
printf("thread1");
calling_to_beacon = 2;
RequestMsg[5] = '2';
TxBytes = write(comfd1, &RequestMsg, 7)
cricket_dist1[0] = GetCricketDist(RxData1, comfd1);
TryLocationCalculation(cricket_dist1, location1);
calling_to_beacon = 4;
RequestMsg[5] = '4';
TxBytes = write(comfd1, &RequestMsg, 7)
cricket_dist1[0] = GetCricketDist(RxData1, comfd1);
TryLocationCalculation(cricket_dist1, location1);
calling_to_beacon = 3;
RequestMsg[5] = '3';
TxBytes = write(comfd1, &RequestMsg, 7)
cricket_dist1[0] = GetCricketDist(RxData1, comfd1);
}
return 0;
}
void *serial_thread_2()
{
while(calling_to_beacon !=0)
{
printf("thread2");
if(calling_to_beacon ==2)
cricket_dist2[0] = GetCricketDist(RxData2,comfd2);
if(calling_to_beacon ==4)
cricket_dist2[0] = GetCricketDist(RxData2,comfd2);
if(calling_to_beacon ==3)
cricket_dist2[0] = GetCricketDist(RxData2,comfd2);
}
}
void *serial_thread_3()
{
while(calling_to_beacon !=0)
{
printf("thread3");
if(calling_to_beacon ==2)
cricket_dist2[0] = GetCricketDist(RxData2,comfd2);
if(calling_to_beacon ==4)
cricket_dist2[0] = GetCricketDist(RxData2,comfd2);
if(calling_to_beacon ==3)
cricket_dist2[0] = GetCricketDist(RxData2,comfd2);
}
}