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
Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
September 25, 2021 while(true) | ||||
---|---|---|---|---|
| ||||
Let's say that I have a simple D program as follows:
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 |
September 25, 2021 Re: while(true) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Selim Ozel | 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:
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
man 2 pause, it sleeps the calling thread until a signal is received. |
September 25, 2021 Re: while(true) | ||||
---|---|---|---|---|
| ||||
Posted in reply to jfondren | On Saturday, 25 September 2021 at 09:46:09 UTC, jfondren wrote: >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:
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
man 2 pause, it sleeps the calling thread until a signal is received. Thanks for the answer. I have actually just re-remembered the thread library in D. Following worked for me.
|
September 25, 2021 Re: while(true) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Selim Ozel | On Saturday, 25 September 2021 at 10:17:32 UTC, Selim Ozel wrote: >Thanks for the answer. I have actually just re-remembered the thread library in D. Following worked for me.
What this program does is run with two threads, one sleeping in a loop and one waiting for the other thread to end. If you're starting a thread so that you can call Thread.sleep in it, that's not necessary. You could just rename |
September 25, 2021 Re: while(true) | ||||
---|---|---|---|---|
| ||||
Posted in reply to jfondren | On Saturday, 25 September 2021 at 10:32:10 UTC, jfondren wrote: >On Saturday, 25 September 2021 at 10:17:32 UTC, Selim Ozel wrote: >Thanks for the answer. I have actually just re-remembered the thread library in D. Following worked for me.
What this program does is run with two threads, one sleeping in a loop and one waiting for the other thread to end. If you're starting a thread so that you can call Thread.sleep in it, that's not necessary. You could just rename That's much better. Thanks a lot. Selim |
September 26, 2021 Re: while(true) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Selim Ozel | On Saturday, 25 September 2021 at 10:37:25 UTC, Selim Ozel wrote: >On Saturday, 25 September 2021 at 10:32:10 UTC, jfondren wrote: >On Saturday, 25 September 2021 at 10:17:32 UTC, Selim Ozel wrote: >[...] What this program does is run with two threads, one sleeping in a loop and one waiting for the other thread to end. If you're starting a thread so that you can call Thread.sleep in it, that's not necessary. You could just rename That's much better. Thanks a lot. Selim Just a reminder, you can also write 5.seconds |
September 26, 2021 Re: while(true) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Imperatorn | On Sunday, 26 September 2021 at 08:50:47 UTC, Imperatorn wrote: >On Saturday, 25 September 2021 at 10:37:25 UTC, Selim Ozel wrote: >On Saturday, 25 September 2021 at 10:32:10 UTC, jfondren wrote: >On Saturday, 25 September 2021 at 10:17:32 UTC, Selim Ozel wrote: >[...] What this program does is run with two threads, one sleeping in a loop and one waiting for the other thread to end. If you're starting a thread so that you can call Thread.sleep in it, that's not necessary. You could just rename That's much better. Thanks a lot. Selim Just a reminder, you can also write 5.seconds The final program is.
|