相同优先级线程按照时间片轮番调度
更多...
相同优先级线程按照时间片轮番调度
源码
#include <rtthread.h>
#define THREAD_STACK_SIZE 1024
#define THREAD_PRIORITY 20
#define THREAD_TIMESLICE 10
static void thread_entry(void *parameter)
{
while (1)
{
if (0 == (count % 5))
{
rt_kprintf(
"thread %d is running ,thread %d count = %d\n", value, value, count);
if (count > 200)
return;
}
count++;
}
}
int timeslice_sample(void)
{
thread_entry, (void *)1,
THREAD_STACK_SIZE,
THREAD_PRIORITY, THREAD_TIMESLICE);
thread_entry, (void *)2,
THREAD_STACK_SIZE,
THREAD_PRIORITY, THREAD_TIMESLICE - 5);
return 0;
}