一个线程会从消息队列中收取消息,另一个线程会定时给消息队列发送普通消息和紧急消息
更多...
一个线程会从消息队列中收取消息,另一个线程会定时给消息队列发送普通消息和紧急消息
源码
#include <rtthread.h>
#define THREAD_PRIORITY 25
#define THREAD_TIMESLICE 5
ALIGN(RT_ALIGN_SIZE)
static char thread1_stack[1024];
static void thread1_entry(void *parameter)
{
char buf = 0;
while (1)
{
{
rt_kprintf(
"thread1: recv msg from msg queue, the content:%c\n", buf);
if (cnt == 19)
{
break;
}
}
cnt++;
}
}
ALIGN(RT_ALIGN_SIZE)
static char thread2_stack[1024];
static void thread2_entry(void *parameter)
{
int result;
char buf = 'A';
while (1)
{
if (cnt == 8)
{
{
}
else
{
rt_kprintf(
"thread2: send urgent message - %c\n", buf);
}
}
else if (cnt >= 20)
{
rt_kprintf(
"message queue stop send, thread2 quit\n");
break;
}
else
{
{
}
}
buf++;
cnt++;
}
}
int msgq_sample(void)
{
"mqt",
&msg_pool[0],
1,
sizeof(msg_pool),
{
return -1;
}
"thread1",
thread1_entry,
&thread1_stack[0],
sizeof(thread1_stack),
THREAD_PRIORITY, THREAD_TIMESLICE);
"thread2",
thread2_entry,
&thread2_stack[0],
sizeof(thread2_stack),
THREAD_PRIORITY, THREAD_TIMESLICE);
return 0;
}