Example Active Object (Cont.) And deleting a file handler object: void file_handler_cleanup(file_handler_t fh) { void* thr_retval; /* create 'terminate' command and place on queue. */ struct cmd* cmd = (struct cmd*)malloc(sizeof(struct cmd)); cmd->cmd = CMD_TYPE_TERM; pthread_mutex_lock(&fh->q->mutex); q_insert(fh->q, cmd); pthread_cond_signal(&fh->q->cond); pthread_mutex_unlock(&fh->q->mutex); /* wait for internal thread to terminate. */ pthread_join(fh->intern_thread, &thr_retval); q_free(fh->q); free(fh); }