Agreed.  I think adding a pthread_mutex_lock is a good idea.