我有一个脚本可以在 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
这是代码的前 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;
有什么想法为什么会发生这种情况吗?
根据有关 pthread_barriers 的信息 http://pubs.opengroup.org/onlinepubs/007904975/functions/pthread_barrier_wait.html在 opengroup.org 上,障碍定义在optionalPOSIX 标准的一部分;选项的名称是“(高级实时线程)”,有时更准确地称为“BAR,障碍(实时)”。
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap02.html http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap02.html
系统可能支持由以下符号常量表示的一个或多个选项(请参阅选项):
_POSIX_BARRIERS
因此,只有当 _POSIX_BARRIERS 宏定义为正数时,才可以使用 pthread_barrier_t 或 pthread_barrier_wait。
Mac OS X 符合 POSIX 标准,但无法在线获取已实施选项的完整列表。有一封信 http://lists.apple.com/archives/unix-porting/2006/Mar/msg00021.html从 2006 年起就出现在苹果邮件列表中,其中表示 Mac OS X 中没有任何障碍。
我知道 Solaris 的 pthread_barrier 也有一些问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)