how to initialize a sem_t variable

537 views Asked by At

I am getting a seg fault at sem_init. I am trying to create a unnamed sem. Thank you Appreciate some help on this.

sem_t *t;

int status = sem_init(t,1,1);
1

There are 1 answers

0
Quimby On
sem_t t;

int status = sem_init(&t,1,1);

This is C API, so all functions use pointers, not references.

Furthermore there are no constructors, hence the existence of sem_init which is used to initialize a structure object t.

It doesn't allocate an object, double ptr would be needed for that.

See e.g. man 3 sem_wait for an example.