The FAQ mentions that there are some problems with condition variables and I
seem to get false reports about destroying waited on condition variables from
Helgrind. I'm using really simple code like the following:
struct linted_array_queue
{
pthread_mutex_t mutex;
pthread_cond_t on_empty;
pthread_cond_t on_full;
size_t message_size;
bool occupied;
char message_buffer[];
};
static void unlock_routine(void* arg)
{
pthread_mutex_t* mutex = arg;
pthread_mutex_unlock(mutex);
}
void linted_array_queue_send(struct linted_array_queue* queue,
void const* message)
{
pthread_mutex_lock(&queue->mutex);
pthread_cleanup_push(unlock_routine, &queue->mutex);
while (queue->occupied) {
pthread_cond_wait(&queue->on_empty, &queue->mutex);
}
queue->occupied = true;
memcpy(queue->message_buffer, message, queue->message_size);
pthread_cond_signal(&queue->on_full);
pthread_cleanup_pop(true);
}
I think it is correct but maybe Helgrind can't deal with condition variables and
cancellation. Is there any metadata or markup I can use to please Helgrind?
|