The problem of compiling Pthread and gcc on OS X

I have a script that compiles fine on Linux (Ubuntu 11.04) but not on 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 

Here are the first 22 lines of code:

 #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; 

Any ideas why this is happening?

+4
source share
2 answers

According to pthread_barriers on opengroup.org, barriers are defined in the optional part of the POSIX standard; the name of the option is (ADVANCED REALTIME THREADS), sometimes more accurately called "BAR, barriers (in real time)."

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

The system can support one or more parameters (see Parameters), denoted by the following symbolic constants:

 _POSIX_BARRIERS 

So, only if the macro _POSIX_BARRIERS is defined as a positive number, can you use pthread_barrier_t or pthread_barrier_wait.

Mac OS X is POSIX compatible, but the full list of options is not available on the Internet. In 2006, there was a letter on the list of apple services stating that there were no barriers in Mac OS X.

I know Solaris had problems with pthread_barrier.

+13
source

As mentioned in OSGX, there are no barriers implemented in OS X, but you can always implement it or just use this implementation. A quick note about the previous implementation, you can use the macro specified by osgx, _POSIX_BARRIERS, rather than the ones indicated on the blog, for example #if !_POSIX_BARRIERS

+3
source

Source: https://habr.com/ru/post/1391758/


All Articles