我似乎无法让netbeans识别pthread_barrier_t类型.我可以输入#include< pthread.h>好吧,但是pthread_barrier_t没有运气.
以下是构建和错误:
g++ -lpthread -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o
build/Debug/GNU-MacOSX/main.o main.cpp main.cpp:32: error:
‘pthread_barrier_t’ does not name a type
我使用的是Netbeans 7.1,我使用的是Mac OSX 10.7.2
我可以创建没有任何编译问题的线程.
bool isNotInSteadyState()
{
int rc = 0;
threadData threadDataArray[NUM_THREADS];
int dataArrayCount = 0;
if (NUM_THREADS < ((PLATE_SIZE - 2) * (PLATE_SIZE - 2)))
{
for (int i = 1; i < PLATE_SIZE - 1; i += sqrt(NUM_THREADS))
{
for (int j = 1; j < PLATE_SIZE - 1; j += sqrt(NUM_THREADS))
{
threadDataArray[dataArrayCount].endY = i + sqrt(NUM_THREADS) - 1;
threadDataArray[dataArrayCount].x = i;
threadDataArray[dataArrayCount].endY = j + sqrt(NUM_THREADS) - 1;
threadDataArray[dataArrayCount++].y = j;
pthread_t* thread;
int pthread_create(thread, NULL,isNotInSteadyStateCheckRunInParallel, &threadDataArray[dataArrayCount]);
if (dataArrayCount >= NUM_THREADS)
{
//pthread_barrier_init(pthread_barrier_t * barrier,
//const pthread_barrierattr_t *restrict attr, NUM+THREADS);
}
if (rc != 0)
{
fprintf(stderr, "Steady State check failed!\n");
}
}
}
}
}
思考?
谢谢,
解决方法:
根据opengroup.org上的info about pthread_barriers,POSIX 1003.1 2004版的可选部分定义了障碍;选项的名称是“(ADVANCED REALTIME THREADS)”,有时更准确地称为“BAR,障碍(实时)”.
所有POSIX选项都列在here中
2.1.3 POSIX Conformance
POSIX System Interfaces
The system may support one or more options (see Options) denoted by the following symbolic constants:
_POSIX_BARRIERS
因此,只有将_POSIX_BARRIERS宏定义为正数,才能使用pthread_barrier_t或pthrad_barrier_wait.
Mac OS X符合POSIX标准,但我找不到完整的选项列表.我知道Solaris也存在pthread_barrier问题. 0700在2006年的苹果主列表中.它表示Mac OS X中没有障碍