设置优先级后,创建线程,在Android平台生效
pthread_attr_t attr;
struct sched_param sched_param;
pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, SCHED_RR);
sched_param.sched_priority = sched_get_priority_max(SCHED_RR);
pthread_attr_setschedparam(&attr, &sched_param);
pthread_create(&pthread_t, 0, &wrapper, self);
pthread_attr_destroy(&attr);
创建后设置优先级,在ARM A7平台生效
pthread_create(&pthread_t, 0, &wrapper, self);
printf("################start###################\n");
pthread_attr_t attr;
struct sched_param sched_param;
struct sched_param param;
int policy;
sched_param.sched_priority = sched_get_priority_max(SCHED_RR);//获取最高优先级,一般是99
pthread_setschedparam(pthread_t, SCHED_RR, &sched_param);
pthread_getschedparam(pthread_t, &policy, ¶m);
printf("priority = %d\n", param.sched_priority);
switch (policy) {
case SCHED_FIFO:
printf ("policy = SCHED_FIFO\n");
break;
case SCHED_RR:
printf ("policy = SCHED_RR\n");
break;
case SCHED_OTHER:
printf ("policy = SCHED_OTHER\n");
break;
default:
printf ("policy = UNKNOWN\n");
break;
}
printf("################end###################\n");