Re: What if I only want to sleep for milliseconds?

new topic     » goto parent     » topic index » view thread      » older message » newer message
CladStone said...

Two answers may be plenty, but here's one more way for Win32 - this is the what I use.

Just link to kernel32.dll and use that function:

global constant 
 cSleep = define_c_proc( 
  kernel32, "Sleep", -- msdn2.microsoft.com/en-us/library/ms686298.aspx 
  {DWORD}), -- milliseconds to sleep. 
   -- A value of zero causes the thread to relinquish the remainder of its time slice 
   --  to any other thread of equal priority that is ready to run. 
   --  If there are no other threads of equal priority ready to run, 
   --  the function returns immediately, and the thread continues execution. 

Notes:
- Just wrap cSleep into whatever routine structure is convenient for you.
- DWORD = C_ULONG = C_UINT = #02000004 (see dll.e)

Yes, that is the exact routine that is called by eu4's sleep(). In linux, there is an equivalent function that is called. Also, by the way, multitasking now uses that when there is idle time between scheduled tasks. (Previously, less than 1 second of time between tasks would cause 100% CPU usage because the task scheduler used active waiting.) There is also a new multi-tasking funtion called task_delay().

One more thing: I noticed that the documentation for sleep() doesn't really put an emphasis on the fact that it now accepts non-integers. Don't you think it should tell exactly how precise it is now? I believe it is milliseconds in Windows, and nanoseconds in linux. I don't know what it is in DOS. Could someone add that to the docs, please?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu