How to: Different functions modifies one data structure

You may want to add a bool to it that locks it, and set it to locked when one thing starts to modify it, then unlock when it is finished. Only allow modification if it’s not locked. You could use a timer to keep trying to modify until it’s not locked.