I have a global variable named my_list containing a linked list (i.e., the variable is a pointer to the first member of the list). This variable can be edited only by two threads, thread A and thread B. In case the list becomes empty, the variable is set to NULL. When this happens the variable is set to NULL first, and afterwards the memory is freed.
As it is edited by two threads, I use a mutex every time thread A or thread B touch the my_list variable. Nothing unusual so far.
But then comes a third thread, thread C. This thread will never ever touch the linked list in any way, but it will need to know from time to time whether the list is empty or not. So, the only thing thread C will do is
if (my_list) {
do_something_completely_unrelated();
}
Do I have to use a mutex for that? I believe it is an atomic operation, so no mutex is required. Is this correct?
EDIT
I will add here a bit of context. The reason why I would like to avoid using a mutex is that the list gets updated rarely (always), but the check coming from thread C happens every few milliseconds, so the less operations the better.
If the list appears to be non-NULL, then a proper check using a mutex is triggered by thread C, and if it is confirmed that the list is not empty thread C stops its obsessive check.