You need use locks to synchronize concurrent access to shared objects, the easiest scenario would be like:
lock_t l; // defines a lock of your system// thread 1:lock(l);counter += 1;unlock(l);// thread 2:lock(l);do_something(counter);unlock(l);
You need use locks to synchronize concurrent access to shared objects, the easiest scenario would be like:
lock_t l; // defines a lock of your system// thread 1:lock(l);counter += 1;unlock(l);// thread 2:lock(l);do_something(counter);unlock(l);