sleeping and resuming a thread