当前位置: 技术问答>linux和unix
POSIX线程中多个线程可以共用一个属性吗?
来源: 互联网 发布时间:2016-08-21
本文导语: 我想创建好几个detached 线程,可以只设置一个attr对象,然后让他们共享么?比如这样: pthread_t thread1,thread2,thread3; pthread_attr_t thread_attr; pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);...
我想创建好几个detached 线程,可以只设置一个attr对象,然后让他们共享么?比如这样:
pthread_t thread1,thread2,thread3;
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);
pthread_craete(&thread1, &thread_attr, thread_function, (void *)message);
pthread_craete(&thread2, &thread_attr, thread_function, (void *)message);
pthread_craete(&thread3, &thread_attr, thread_function, (void *)message);
pthread_t thread1,thread2,thread3;
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);
pthread_craete(&thread1, &thread_attr, thread_function, (void *)message);
pthread_craete(&thread2, &thread_attr, thread_function, (void *)message);
pthread_craete(&thread3, &thread_attr, thread_function, (void *)message);
|
当然可以因为属性参数是const的。
#include
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg);