
pthread_create(pthread_t *tid, pthread_attr_t *attr, (void *)(*runtime)(void *), void *arg);
pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_setinheritsched(pthread_attr_t *attr,intinheritsched)。int pthread_attr_setinheritsched(pthread_attr_t*attr,intinheritsched)。int pthread_attr_getdetachstate(pthread_attr_t *attr,int detachstate)。

pthread_attr_getinheritsched(pthread_attr_t *attr, int *inheritsched);
pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
pthread_attr_getschedpolicy(pthread_attr_t *attr, int *policy);

int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)。int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)。int pthread_attr_setschedparam(pthread_attr_t *attr,const struct sched_param *param)。
struct sched_param param。 struct sched_param param。memcpy (&new_thread->p_start_args.schedparam, &attr->__schedparam,sizeof (struct sched_param))。
pthread_setschedparam(pthread_t *pid, int policy, const struct sched_param *param);

pthread_getschedparam(pthread_t *pid, int *policy, struct sched_param *param);
struct sched_param {
int __sched_priority;

};
函数pthread_attr_setinheritsched和pthread_attr_getinheritsched用于设置及获得线程的继承属性pthread 设置优先级。继承属性分两种:PTHREAD_EXPLICIT_SCHED表示创建子线程的时候不继承父线程的调度策略;PTHREAD_INHERIT_SCHED表示创建了线程的时候继承父线程的调度策略,在这种情况下,用户设置的线程调度策略将被忽略。在Linux中,有三种线程调度策略:SCHED_FIFO(此策略允许一个线程一直运行,直到具有较高优先级的另一个线程已准备好运行,或者直到当前线程自动阻止);SCHED_RR(此策略与 SCHED_FIFO 策略相同,不同的只是运行的线程在被占据之前只能运行有限的时间长度)SCHED_OTHER(此策略为不具有实时性没有优先级的策略)。系统默认的线程调度策略为SCHED_OTHER,通过函数pthread_attr_setschedpolicy和pthread_attr_getschedpolicy可以设置及获得线程调度策略。当线程调度策略设置成SCHED_FIFO或SCHED_RR后就可以通过pthread_attr_setschedparam和pthread_attr_getschedparam来设置及获得线程优先级了。然后,就可以用设置好的属性来创建线程pthread 设置优先级。当线程创建好过后,还可以调用pthread_setschedparam和pthread_getschedparam来设置和获得线程属性。
注意:程序必需以系统管理员的身份才能运行,不然创建线程不成功。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-102728-1.html
冷静
我们以确认美以进我12海里就该打沉它
这样的人也能被称为教授