You can't in plain C++. You'll need to use an OS-specific mechanism, and you need a point where execution is suspended in a way that allows the OS to execute the callback. E.g. for Windows, QueueUserAPC
- the callback will be executed when you e.g. SleepEx
or WaitForSingleObjectEx