Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OSX上的Pthread和gcc编译问题_C_Macos_Gcc_Compiler Errors_Pthreads - Fatal编程技术网

OSX上的Pthread和gcc编译问题

OSX上的Pthread和gcc编译问题,c,macos,gcc,compiler-errors,pthreads,C,Macos,Gcc,Compiler Errors,Pthreads,我有一个在Linux(Ubuntu11.04)上编译得很好的脚本,但在OSX(Lion)上编译不好 下面是代码的前22行: #include <stdlib.h> #include <stdio.h> #include <time.h> #include <math.h> #include <sys/time.h> #include <pthread.h> #include <assert.h> /* crea

我有一个在Linux(Ubuntu11.04)上编译得很好的脚本,但在OSX(Lion)上编译不好

下面是代码的前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;
#包括
#包括
#包括
#包括
#包括
#包括
#包括
/*为thr_func()创建线程参数结构*/
类型定义结构线程数据{
国际贸易署;
整数*整数;
整数*和;
int num_int;
内部*温度;
}线程数据;
常数int MIN_RAND_int=1;
常数int MAX_RAND_int=65000;
//pthreads屏障变量
pthread_barr_t barr;
知道为什么会发生这种情况吗?

根据opengroup.org上的信息,在POSIX标准的可选部分中定义了障碍;选项的名称是“(高级实时线程)”,有时更确切地称为“栏、屏障(实时)”

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

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

Mac OS X符合POSIX标准,但无法在线获得完整的已实施选项列表。在苹果2006年发布的mainling排行榜上,苹果称MacOSX没有任何障碍


我知道Solaris在pthread_barrier上也有一些问题。

正如osgx所提到的,屏障并没有在OSX上实现,但您可以始终实现它或只使用实现。在前面的实现中,您可以使用osgx提到的宏,而不是博客上的那些,比如
#if!定义的| | | | POSIX_BARRIERS<0

似乎没有定义pthread_barrier\t。据我所知,这是pthread库定义的类型,可能没有
pthread_barrier\t
。关于这一点的一些提示已经在问号中提到了,这澄清了这一点。Linux的胜利:)谢谢,OSX似乎有点像是2001年左右冻结的POSIX。帮助人们编写符合现代标准的代码似乎不是他们的首要目标。
#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;
_POSIX_BARRIERS