我想在 netbeans 中编写一些学校的 C 任务。他们给了我们必须使用 pthread_barrier 的任务。所以我下载了netbeans和cygwin以及gcc、g++、gdb和make。在pthreads.h
中没有任何pthread_barrier_t
等。在this question中我发现“障碍是在 POSIX 1003.1 2004 版的可选部分中定义的”。问题是如何在 cygwin 中使用 netbeans 中的屏障?
一些代码:
//#define _POSIX_BARRIERS 1
//I don't get it what they mean
//"only if the _POSIX_BARRIERS macro is defined as positive number,
//you can use pthread_barrier_t"
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
// declaration of the barrier
pthread_barrier_t a_barrier; // err: Unable to resolve identifier pthread_barrier_t.
最佳答案
Cygwin 目前不支持 pthread_barrier_*
,因此您将无法在 Cygwin 上编译或运行需要这些功能的代码。
关于Netbeans 中的 C pthread_barriers (cygwin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27650215/