Problem seems to be in synchronization of the threads. Can you please answer my other thread in this forum "synchronizing two threads".

In this post I would like you to help me where I am taking out the smallest packet from the list. I need not to wait using sleep() or usleep() for the system clock time to reach the packet time stamp. Can you please tell me how is it possible that I'll read the smallest packet and send it only when the system clock time is reached. If I Search in the list with the smallest packet and in match case if I use the system clock time to check with the packet time stamp. How this can be good enough to do the task? Here is the code. Thanks for your replies.

Code:
 while(scurr->next!=NULL) // checking for the entire list
     {
       // this if is finding the packet with smallest time stamp
       if(snode->ts.tv_sec < scurr->ts.tv_sec && snode->ts.tv_usec < scurr->ts.tv_usec)
        {
          TMPNode=snode;
          snode=scurr;
          scurr=TMPNode;
        }
       
       scurr=scurr->next;
     }
   
      gettimeofday(&curr_time,NULL);      
// this if is checking the smallest packet with the system clock time
       if(curr_time.tv_sec >= snode->ts.tv_sec  && curr_time.tv_usec >= snode->ts.tv_usec)
     {
       
       struct sockaddr_ll destAddr;
       memcpy(buf,&snode->pkt,snode->pkt_len);
       memcpy(&(destAddr.sll_addr),&buf,MAC_ADDR_LEN);
       destAddr.sll_family=PF_PACKET;
       destAddr.sll_protocol=htons(ETH_P_ALL);
       destAddr.sll_ifindex=2;
       destAddr.sll_pkttype=PACKET_OTHERHOST;
       destAddr.sll_halen=ETH_ALEN;
       if(snode2->rFlag==0 && snode2->wFlag==1)
         {
           // here I am writing the data on the wire
           if((retVal=write(Fd,snode->pkt,snode->pkt_len))==-1)
         {
           printf("retVal is %d",retVal);
           printf("sendto() error \n");
         }
           printf("SENDER 1 --- packet number is %d OF length %d Sent \n",snode2->pkt_id,retVal);
           snode2->rFlag=1;
           snode2->wFlag=0;
         }
       
     }
       snode=snode->next;
  }while(snode->next != NULL);