while(true)

jfondren julian.fondren at gmail.com
Sat Sep 25 09:46:09 UTC 2021


On Saturday, 25 September 2021 at 09:35:16 UTC, Selim Ozel wrote:
> Let's say that I have a simple D program as follows:
> ```
> void main() {
>   while(true) {
>   }
>   assert(false);
> }
> ```
>
> It will run until killed. It also uses a lot of CPU. Is there a 
> good DLang way to make it use less CPU?
>
> Selim

```d
void main() {
     import core.sys.posix.unistd : pause;

     while (true) {
         pause;
     }
     assert(false);
}
```

man 2 pause, it sleeps the calling thread until a signal is 
received.


More information about the Digitalmars-d mailing list