In unix I can safely modify a variable within a thread using a mutex lock like-so:
unix
mutex lock
int x = 0; // Global Variable we want to modify b