OS X上的Pthread和gcc编译问题

Dol*_*cci 4 c macos gcc compiler-errors pthreads

我有一个在Linux上编译好的脚本(Ubuntu 11.04),但在OS X(Lion)上却没有.

gcc -pthread -o hw1 hw1.c 
hw1.c:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘barr’
hw1.c: In function ‘__syncthreads’:
hw1.c:53: error: ‘barr’ undeclared (first use in this function)
hw1.c:53: error: (Each undeclared identifier is reported only once
hw1.c:53: error: for each function it appears in.)
hw1.c:54: error: ‘PTHREAD_BARRIER_SERIAL_THREAD’ undeclared (first use in this function)
hw1.c: In function ‘parallel_psum’:
hw1.c:94: error: ‘barr’ undeclared (first use in this function)
hw1.c:107: warning: assignment from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)

这是代码的前22行:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <sys/time.h>
#include <pthread.h>
#include <assert.h>

/* create thread argument struct for thr_func() */
typedef struct _thread_data_t {
    int tid;
    int* ints;
    int* sums;
    int num_ints;
    int* temp;
} thread_data_t;

const int MIN_RAND_INT = 1;
const int MAX_RAND_INT = 65000;

// pthreads barrier variable
pthread_barrier_t barr;
Run Code Online (Sandbox Code Playgroud)

任何想法为什么会这样?

osg*_*sgx 14

根据有关opengroup.org上pthread_barriers的信息,在POSIX标准的可选部分中定义了障碍; 选项的名称是" (ADVANCED REALTIME THREADS) ",有时更准确地称为"BAR,障碍(实时)".

http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap02.html

系统可能支持以下符号常量表示的一个或多个选项(请参阅选项):

_POSIX_BARRIERS
Run Code Online (Sandbox Code Playgroud)

因此,只有将_POSIX_BARRIERS宏定义为正数时,才能使用pthread_barrier_t或pthread_barrier_wait.

Mac OS X符合POSIX标准,但未在线提供完整的已实施选项列表.2006年的苹果主播清单中有一封信,其中表示Mac OS X中没有障碍.

我知道Solaris也有一些pthread_barrier的问题.