I found out about using condition variable [1] and implemented one to get this behavior. Thanks anyways :)

[1] en.cppreference.com/w/cpp/thread/condition_variable

Read More...