user9791370
user9791370

Reputation: 339

How can I find out how much time was left to sleep after thread was interrupted?

I have a thread, on which i am calling sleep() for a specific amount of time. If the thread is interrupted, I need a way to know how much time was left. Is there a built-in way to do this?

P.S. I have a strong suspicion that this may be an XY problem. (i.e. I'm thinking about this completely wrong)

Upvotes: 2

Views: 148

Answers (1)

daniu
daniu

Reputation: 14999

When starting the sleep, determine the end of sleep first. If the sleep is interrupted and should be resumed, sleep for originalEndTime - now ms.

It's so not clear what exactly you're trying to do though tasks, you're probably right about the XY.

Upvotes: 1

Related Questions