int create_comm_thread(pthread_t *pth, void*(*func)(void *), void *arg,
int policy, int prio)
{
int ret;
struct sched_param schedp;
pthread_attr_t attr;
pthread_attr_init(&attr);
memset(&schedp, 0, sizeof(schedp));
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
if (ret) {
printf("pthread_attr_setinheritsched:%d\n", ret);
return -1;
}
ret = pthread_attr_setschedpolicy(&attr, policy);
if (ret) {
printf("pthread_attr_setschedpolicy:%d\n", ret);
return -1;
}
schedp.sched_priority = prio;
ret = pthread_attr_setschedparam(&attr, &schedp);
if (ret) {
printf("pthread_attr_setschedparam:%d\n", ret);
return -1;
}
ret = pthread_create(pth, &attr, func, arg);
if (ret) {
printf("pthread_create:%d\n", ret);
return -1;
}
return 0;
}
创建线程优先级
{
pthread_t blocker;
pthread_attr_t attr1;
int policy;
pthread_attr_getschedpolicy( &attr1, &policy );
switch ( policy )
{
case SCHED_FIFO:
break;
case SCHED_RR:
break;
case SCHED_OTHER:
break;
default:
break;
}
//struct thread_arg blocker_arg = THREAD_ARG_INITIALIZER;
create_comm_thread(&blocker, mav2_camera_thread_proc,
NULL, SCHED_RR, 99);
}