sync handlers in multithreaded program