On Saturday, 17 August 2024 at 19:49:04 UTC, Vinod K Chandran wrote:
>All I want is a delay function which simulate some work load in current thread.
As Rikki points out, delay or sleep functions (as the name says) ‘put the thread to sleep’. If you want the thread to be constantly busy, you can use a while loop:
import core.time;
//waste electricity for 1ms:
const endTime = MonoTime.currTime + 1.msecs;
while(MonoTime.currTime < endTime){}
Note that it’s better to let the thread rest because otherwise the OS might be starved for threads, or the CPU will consume more electricity and could overheat unnecessarily, hindering your program’s performance.