Subj : condvar wait / signal on arbitrary object To : comp.programming.threads From : Michael B Allen Date : Tue Jul 12 2005 03:46 pm I just had a thought and I'd like your opinion. Instead of embedding a condition variable in each object one would want to wait and signal on, the object could be used as a key to lookup a condvar by it's address modulo the size of an array of convars. This has the benifit of permitting one to wait on an arbitrary object (like Java except you can specify the mutex to unlock). For example: #define CONDVAR_ARRAY_SIZE 17 struct ctx { pthread_cond_t array[CONDVAR_ARRAY_SIZE]; }; int ctx_pthread_cond_wait(struct ctx *ctx, void *obj, pthread_mutex_t *mutex) { pthread_cond_t *cond = ctx->array[(size_t)obj % CONDVAR_ARRAY_SIZE]; return pthread_cond_wait(cond, mutex); } int ctx_pthread_cond_signal(struct ctx *ctx, void *obj, pthread_mutex_t *mutex) { pthread_cond_t *cond = ctx->array[(size_t)obj % CONDVAR_ARRAY_SIZE]; return pthread_cond_broadcast(cond); } Of course depending on the table size there could be many spurious wakeups. What do you think? Good idea or should I not bother? Thanks, Mike .