POSIX线程中多个线程可以共用一个属性吗?
我想创建好几个detached 线程,可以只设置一个attr对象,然后让他们共享么?比如这样:
[code=C/C++][/code]
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的。
C/C++ code
#include <pthread.h>
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg);