• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[C] Timed Cycle

Newbie Spellweaver
Joined
Aug 21, 2005
Messages
84
Reaction score
0
hi guys

i want to ask a question... does anyone know a good way to make timed cycle? because using for (i=0;i<20000000000000000000000000000;i++) works really differently on different pc...
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
Try and look for sleep functions, these delay the execution of the program instead of looping (and thus using CPU!). Always use sleep and no loops for this.

windows.h has a Sleep() function, google it.
 
Newbie Spellweaver
Joined
Aug 21, 2005
Messages
84
Reaction score
0
okay, so i have found sleep () function for linux in unistd.h but the problem is that it works with Seconds, not miliseconds... any advices?
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
microsleep() ? Perhaps working with decimals works...10 ms is the lowest you can get though (depending on your CPU), even if you say it should be 1 ms.
 
Newbie Spellweaver
Joined
Aug 21, 2005
Messages
84
Reaction score
0
ty 4 help but i've found a better thing
usleep



WTB lib and command to change color -.- not whole screen text but some specific output and etc
 
Newbie Spellweaver
Joined
Nov 28, 2006
Messages
56
Reaction score
0
Try and look for sleep functions, these delay the execution of the program instead of looping (and thus using CPU!). Always use sleep and no loops for this.

windows.h has a Sleep() function, google it.

Also take into account that if you use the sleep fuction on a singel threaded program it will HANG ON for the said number of seconds.
 
Back
Top