Jump to content

sleep, interrupts, wait,


Recommended Posts

Experienced users please correct any of these assumptions if wrong.

-- There are 2 ways to have a script "run"

1. You can do GuiGetMsg and see what has been pressed.

2. You can set up GuiCtrlSetOnEvent to run a function when a button is clicked, or a field is changed.

In case (2), the main program in examples seems to be "while 1 / sleep(1000) / wend", so does "nothing" However, you can't do any non-event-driven processing, unless you do something like: "while 1 / sleep(1000) / call(mystuff) / wend".

In case 1, I put in a counter to see how often GuiGetMsg was executed - and it is a LOT. I am assuming that when it is called with a 0, that it is "giving you time to do stuff" i.e. giving you your "time slice", and at a minimum you can just return.

What I'm running into, is that if I do a type (1) above, and stick a sleep in it, I do significantly reduce the CPU time the script takes, but my responsiveness seems to go to bad because I assume so many msgs are stacked up my -- for example -- close, is 5000'th in line behind the time slices "or something".

If I take out the sleep, it closes almost instantly upon pressing a close button or the [x] etc.

I would assume that if you can write a program in style (2) that you are taking virtually NO cycles (except to set up another sleep(1000)) every second, until someone clicks something etc.

That makes (2) the ideal -- best performing way. BUT THEN, I wanted to write a program "is the internet up?" which might for example ping some known place, then "go to sleep for 30 seconds" and ping again.

I could not find any kind of function I've seen in other "operating systems" such as "interrupt me in 30 seconds" then you get NO cycles until your "timer expired" interrupt fired off to give you control.

I know I could read the time, in a loop, etc, but that's "bad" (takes cycles) vs some kind of "timer" that counts down with extremely low overhead, THEN runs your routine (to do another ping, etc).

P.S. my most frequently used AUTOIT script is one that sees if a window that FTP lost its connection is being displayed, and restarts it. I find with a flaky line, or whatever is breaking my FTP connection, it can restart say 40 times overnight, and I can have transferred a gig of data, rather than breaking and not knowing about it until the AM and manually restarting!

Kudos to all the developers!

Ward Christensen

Inventor of Xmodem & (w/Randy Suess), BBSs. (30 yr anniv 2/16/2008)

Link to comment
Share on other sites

I assume you script has a GUI as well. :) In a loop with GUIOnEventMode on, a sleep to a value of 1000, is rather large. Usually a sleep of around 10ms is sufficent. In GUIGetMsg, the function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU. You are correct when assuming that your messages will get banked up. It does become noteable on slower systems even more so, so it's probably best not to have a sleep in the loop in this instance.

Good luck in finding the rest of your wants/hopes/aspirations, as I'm not really sure how you can implement them, if I understand what you are asking correctly.

Cheers,

Brett

:)

Link to comment
Share on other sites

Thanks, Brett, the other part was simply wanting my script to go to sleep for 5 minutes, then wake up, try a ping again, go back to sleep, etc. I don't want to do a 5 minute sleep within guigetmsg, or my program won't exit.

I did "hack" an answer to my own question - do a very small sleep (100ms?) then COUNT the # until I have my 5 minutes (or better, check by the "wall clock") but that seems to burn cycles unnecessarily. I would like to have zero cycles (just because it seems right, not because I can't afford them) but have an "interrupt" come in when say close is clicked (I can do that) or when my "timer has expired" (of which I can find no such thing).

By analogy: Consider a PING command.

You say "ping something, with a 500ms timeout"

I'm sure the underlying program sends a ping, hooks in an interrupt for when it comes back, *AND* sets an OS-based timer to interrupt in 500ms.

THEN if the ping responds, it cancels the 500ms timer, or if the 500ms timer goes off, it cancels the ping.

It is this 500ms part - i.e. wake me up after some amount of time - that I can't seem to find in AUTOIT.

sort of like:

Func timer_expired()

myping()

endfunc

end_button_pushed()

exit

endfunc

i.e. there is no guigetmsg, just hanging around waiting for timers, buttons, etc.

Link to comment
Share on other sites

Thanks, Brett, the other part was simply wanting my script to go to sleep for 5 minutes, then wake up, try a ping again, go back to sleep, etc. I don't want to do a 5 minute sleep within guigetmsg, or my program won't exit.

I did "hack" an answer to my own question - do a very small sleep (100ms?) then COUNT the # until I have my 5 minutes (or better, check by the "wall clock") but that seems to burn cycles unnecessarily. I would like to have zero cycles (just because it seems right, not because I can't afford them) but have an "interrupt" come in when say close is clicked (I can do that) or when my "timer has expired" (of which I can find no such thing).

By analogy: Consider a PING command.

You say "ping something, with a 500ms timeout"

I'm sure the underlying program sends a ping, hooks in an interrupt for when it comes back, *AND* sets an OS-based timer to interrupt in 500ms.

THEN if the ping responds, it cancels the 500ms timer, or if the 500ms timer goes off, it cancels the ping.

It is this 500ms part - i.e. wake me up after some amount of time - that I can't seem to find in AUTOIT.

sort of like:

Func timer_expired()

myping()

endfunc

end_button_pushed()

exit

endfunc

i.e. there is no guigetmsg, just hanging around waiting for timers, buttons, etc.

TimerInit, AdlibEnable and polling the timer could work... :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...