fix race condition, use wait/notify