Home > pthread cond > pthread_cond_initializer error

Pthread_cond_initializer Error


here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow pthread_cond_initializer example the company Business Learn more about hiring developers or posting ads with us Stack

Pthread_cond_t Example

Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of pthread_condattr_t 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why PTHREAD_COND_INITIALIZER may be used to initialize a condition variable only when it is declared? up vote 4 pthread_cond_destroy down vote favorite Since the PTHREAD_COND_INITIALIZER is actually a structure initializer, it may be used to initialize a condition variable only when it is declared. From: Multi-Threaded Programming With POSIX Threads Question: Couldn't understand the above quote. It is just a macro, why can't I use it to initialize the condition variable on run time? What has its being a structure initializer to do with anything? multithreading pthreads share|improve this question asked

Pthread_cond_init Example C

Feb 27 '12 at 10:36 Aquarius TheGirl 4,83528106205 add a comment| 2 Answers 2 active oldest votes up vote 7 down vote accepted Because it is a structure initializer, you cannot use it to init the structure in a statement apart from its declaration. It is defined on my system like so: #define PTHREAD_COND_INITIALIZER {_PTHREAD_COND_SIG_init, {0}} Expanded and used, we see: pthread_cond_t p = PTHREAD_COND_INITIALIZER; // << ok! p = PTHREAD_COND_INITIALIZER; // << compiler error =\ That is, p = PTHREAD_COND_INITIALIZER; expands to: p = {_PTHREAD_COND_SIG_init, {0}}; share|improve this answer answered Feb 27 '12 at 10:52 justin 89.6k10142189 1 Since you've shown the code, I understand the meaning. Thanks, didn't know the "term" structure initializer. Very helpful. –Aquarius TheGirl Feb 27 '12 at 10:55 2 @AnishaKaul you're welcome. note also that you could reinitialize it using C99 compound literals, provided of course it either failed initialization or has been destroyed, and your compiler supports C99 compound literals (not always C++ friendly). Here's the form: p = (pthread_cond_t)PTHREAD_COND_INITIALIZER; -- which expands to p = (pthread_cond_t){_PTHREAD_COND_SIG_init, {0}};. –justin Feb 27 '12 at 11:16 add a comment| up vote 0 down vote For g++, use -std=c++0x parameter and your problem should be solved. share|improve this answer edited Feb 24 '15 at 21:39 kenorb 22.2k9155128 answe


Related content

No related pages.