Added timeout

Added timeout on wait() in case the child thread doesn't return.