我想在 netbeans 中编写一些学校的 C 任务。他们给了我们必须使用 pthread_barrier 的任务。所以我用 gcc、g++、gdb 和 make 下载了 netbeans 和 cygwin。In pthreads.h
is not any pthread_barrier_t
etc. 在这个问题中,我发现“障碍是在 POSIX 1003.1 2004 版的可选部分中定义的”。Qustion 是如何在 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.