23,121
社区成员
发帖
与我相关
我的任务
分享
//pthread2.c
#include <stdio.h>
#include <pthread.h>
//#include <sys/sched.h>
void encode_thread()
{
}
void decode_thread()
{
}
int main(){
pthread_t id_encode;
pthread_t id_decode;
pthread_attr_t attr;
struct sched_param param;
int newprio;
int ret;
newprio=25;
pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr,SCHED_RR);
pthread_attr_setscope(&attr,PTHREAD_SCOPE_SYSTEM);
pthread_attr_getschedparam(&attr, ¶m);
param.sched_priority=newprio;
pthread_attr_setschedparam(&attr, ¶m);
ret = pthread_create(&id_encode,&attr,(void*)encode_thread,NULL);
if ( 0 != ret )
{
fprintf(stderr, "create encode_thread thread error\n");
return -1;
}
pthread_attr_destroy(&attr);
printf("1.create encode_thread ok!\n");
pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr,SCHED_RR);
pthread_attr_setscope(&attr,PTHREAD_SCOPE_SYSTEM);
newprio=17;
pthread_attr_getschedparam(&attr, ¶m);
param.sched_priority=newprio;
pthread_attr_setschedparam(&attr, ¶m);
ret = pthread_create(&id_decode,&attr,(void*)decode_thread,NULL);
if ( 0 != ret )
{
fprintf(stderr, "create decode_thread thread error\n");
return -1;
}
pthread_attr_destroy(&attr);
printf("2.create decode_thread ok!\n");
return 0;
}
$gcc pthread2.c -lpthread
$./a.out
1.create encode_thread ok!
2.create decode_thread ok!