Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not being able to initialize condition variable in a struct

Tags:

c

pthreads

Why am I not able to initialize a condition variable in a struct? I want each node to have a condition variable so I can wait and signal it, and when I add the initialization code it throws this error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘attribute’ before ‘=’ token make: * [trie.o] Error 1

I tried doing the initializition when needed somewhere(not in the struct)and I still get an error, I have included pthreads.h

struct trie_node {

  pthread_cond_t condition=PTHREAD_COND_INITIALIZER;
};
like image 720
Ozymandy Avatar asked Feb 02 '26 09:02

Ozymandy


1 Answers

You can't use PTHREAD_COND_INITIALIZER when initializing a structure member.

You have to use pthread_cond_init after you create an instance of the structure.

Actually, you can't initialize structure members at all in the structure definition, it's not just this one.

like image 112
Some programmer dude Avatar answered Feb 04 '26 00:02

Some programmer dude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!