Hi,
I want to write a program where one core (core 0) will fill the FIFO and other core (core 1 ) will delete the data from FIFO.
Core 0:
I create a fifo
Code:
struct node
{
int info;
struct node *ptr;
}*front,*rear,*temp,*front1;
and my en-queue function is in core 0 and writing to specific memory location..(which works perfectly)
Code:
void enq(int data)
{
if (rear == NULL)
{
rear = (struct node *)malloc(1*sizeof(struct node));
rear->ptr = NULL;
rear->info = data;
front = rear;
}
else
{
temp=(struct node *)malloc(1*sizeof(struct node));
rear->ptr = temp;
temp->info = data;
temp->ptr = NULL;
rear = temp;
}
}
Now the problem is in the core 1. Here I am unable to read the values from the specific memory location. I am getting garbage value. Where I am doing some stupid error.. I did not understand
Code:
(front->ptr) = (unsigned int *) memory_location;
WHen I print the (front->ptr) it shows correct memory address but inside the
the De-queue function in core 1, I am getting wrong value..
Code:
int deq(int buf[n])
{
front1 = front;
printf("Val %d ", front->info); // showing wrong value
if (front1 == NULL)
{
printf("\n Error: Trying to display elements from empty queue");
return 0;
}
else
if (front1->ptr != NULL)
{
front1 = front1->ptr;
printf("\n Dequed value : %d", front->info);
free(front);
front = front1;
buf[n] = front->info;
}
else
{
printf("\n Dequed value : %d", front->info);
buf[n] = front->info;
free(front);
front = NULL;
rear = NULL;
}
return 0;
}
I already lost more than one day to solve it.. Please help...