#include typedef struct container_lock { int v; pthread_mutex_t l; } container_lock_t ; #define SYNC_START(x) { \ container_lock_t *tmp = x; \ {int *x = &tmp->v; pthread_mutex_lock(&tmp->l); #define SYNC_END } pthread_mutex_unlock(&tmp->l);} void* other_thread(void* arg){ container_lock_t *cl = (container_lock_t *) arg; SYNC_START(cl); //now I hold the lock! cl is just a value in here *cl += 15; SYNC_END; } int main(){ container_lock_t _cl; container_lock_t *cl = &_cl; pthread_mutex_init(&cl->l,0); pthread_t _other_thread; pthread_create(&_other_thread, NULL, other_thread, cl); SYNC_START(cl); //now I hold the lock! cl is just a value in here *cl += 15; SYNC_END; pthread_join(_other_thread, NULL); return cl->v; }