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;
};
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With