LLNL/UnifyFS

Missing locking on sm->time_to_exit

Closed this issue · 2 comments

Hi, developers, lock sm->thrd_lock is used to protect sm->time_to_exit. However, it only protects the write sm->time_to_exit = 1; not the read if (sm->time_to_exit). For mutually exclusive accesses, the locks should be guarding both places.

if (sm->time_to_exit) {
break;

pthread_mutex_lock(&(sm->thrd_lock));
sm->time_to_exit = 1;
pthread_cond_signal(&(sm->thrd_cond));
pthread_mutex_unlock(&(sm->thrd_lock));

This unlocked access to sm->time_to_exit is by design. The variable is initialized to 0, and once it is set to 1, the value will never change. It does not matter for correctness which loop iteration we detect the "time to exit" condition, only that we will eventually. The time window for "eventually" is around 50ms, which is plenty fast for this scenario when we are shutting down the server.

@MichaelBrim Thanks so much for your explanations.