-   Programming (
-   -   Help: Initialize pthread_cond_t (

jaepi 09-19-2007 10:40 PM

Help: Initialize pthread_cond_t
Hello there, I've been messing around with threads these days. Currently, I'm having problems with one of my variables of type pthread_cond_t (let's call it variable Z). I made a class (let's say class X) , and you guessed it right, Z was declared in it with private access level. Now the problem here is the initialization of Z. I initialized it with this value - PTHREAD_COND_INITIALIZER. It produces this error - error: expected primary-expression before '{' token.

This is the way I initialized it.


//code here 

What do you think is the problem?


kev82 09-20-2007 01:22 AM

PTHREAD_COND_INITIALIZER is #defined as an aggregate. On my platform it is {0x3CB0B1BB, {0}}. There is no constructor for pthread_cond_t that accepts an aggregate.

I unfortunately don't have a very good understanding of how aggregates work, and don't know if it is even possible to write a constructor to accept one (I don't think so though). Even if it was, this would require a modification of pthreads to make your code work (very bad idea!).

Bottom line, use pthread_cond_init() in your constructor.

All times are GMT -5. The time now is 03:41 AM.