void main (void)
{
/* create three message queue */
mesgQueueId1 = msgQCreate(MAX_MESSAGES,MAX_MESSAGE_LENGTH,MSG_Q_FIFO);
if((taskIdOne = taskSpawn("t1",90,0x100,20000,(FUNCPTR)t1,0,0,0,0,0,0,0,0,0,0)) == ERROR)
printf("generating task1 failed\n");
if((taskIdThree = taskSpawn("t3",90,0x100,20000,(FUNCPTR)taskThrees,0,0,0,0,0,0,0,0,0,0)) == ERROR)
printf("generating task3 failed\n");
}
void t1(void)
{
timer_t task1;
struct itimerspec value;
value.it_value.tv_sec = 3;
value.it_value.tv_nsec = 0;
value.it_interval.tv_sec = 3;
value.it_interval.tv_nsec = 0;
timer_create (CLOCK_REALTIME, NULL, &task1);
timer_connect (task1, task_1_timers,0);
timer_settime (task1, 0, &value, NULL);
while(1)
sleep(1);
}
void task_1_timers ( timer_t timerid,int myarg )
{
char message[] = "ta";
printf (" task1-3sec\n");
if((msgQSend(mesgQueueId1,message,MAX_MESSAGE_LENGTH, WAIT_FOREVER,MSG_PRI_NORMAL)) == ERROR)
printf("msgQSend in taskOne failed\n");
}
void taskThrees(void)
{
char msgBuf[MAX_MESSAGE_LENGTH];
// receive message from task1
if(msgQReceive(mesgQueueId1,msgBuf,MAX_MESSAGE_LENGTH, WAIT_FOREVER)== ERROR)
printf("msgQReceive in taskTwo failed\n");
else
printf("%s\n",msgBuf);
msgQDelete(mesgQueueId1); /* terminate and free a message queue */
}
output:
task1-3sec
ta
task1-3sec
msgQSend in taskOne failed
task1-3sec
msgQSend in taskOne failed
...
i have problem with this code. the message is not going more than one time. help me !!!
The output should be that this:
output
task1-3sec
ta
task1-3sec
ta
task1-3sec
ta
...
ajay.joshi.56 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.