Due to my feeble understanding of allocating type memory to pointers, the following causes a bus error on the call to barrier_create ("hi" is never printed).
typedef struct barrier barrier_t;
typedef struct barrier *barrier_p;
barrier_p test_barrier_p;
int main(int argc, char *argv[]) {
barrier_create(*test_barrier_p);
}
int barrier_create(barrier_p *barrier_pointer) {
printf("hi\n");
barrier_p old_barrier, new_barrier;
int count;
old_barrier = (barrier_p) *barrier_pointer;
new_barrier = (barrier_p) malloc(sizeof(*new_barrier));
count = pthread_mutex_init(&new_barrier->lock, NULL);
new_barrier->is_valid = VALID_BARRIER;
new_barrier->counter = 0;
new_barrier->release_flag = 0;
*barrier_pointer = new_barrier;
return HAPPY_HAPPY_JOY_JOY;
}
What am I missing or mis-typing?