Jump to content

Multithreading possible?


stigma
 Share

Recommended Posts

Hey all,

I've recently run into a little problem that I don't know how to elegantly script.

Let me explain via an abstract example:

I live in a leaky house, and water drips through the roof into a bucket that occationally gets full an needs to be emptied. I want the script to make me dinner, feed the dog, do the laundry, and most importantly of all empty that bucket as soon as its near full.

The problem of course is that if the bot is in the middle of making dinner or doing something else, it won't even be paying attention to check if the bucket has gotten full, and my floor gets all wet :D

How can I make a script that continously performs a check to see if the bucket is getting full, but at the same time also continues on with its other functions (and just pauses those temporarily when it sees it needs to empty the bucket)?

The only way I know how to make one right now is to manually put in checks into every other method I'm using, but that is a really bad hack, and it quickly becomes too cumbersome.

The other possible way would maybye be to use two scripts simultaniously. One to keep an eye on the bucket, and one to do the other tasks. The problem with this is I don't know if its possible for one script to pass a message to the other script so it can pause itself while the bucket script finishes emptying the bucket.

The third possible way I can think of is doing multithreaded code in the same script, if that is even possible in au3.

So, I am very open to suggestions from the more experienced coders :) What is a good solution for this problem?

-Stigma

Link to comment
Share on other sites

How can I make a script that continously performs a check to see if the bucket is getting full, but at the same time also continues on with its other functions (and just pauses those temporarily when it sees it needs to empty the bucket)?

see AdlibEnable()

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Ah, nice. Looks to be exactly what I need. Thank you :)

I have one more thing I need to figure out for now, and since I got my first answer so striahgtforward I guess I might as well just add it to this thread.

I need a function that allows me to measure how much real-time has passed from point A to point B in a script. I looked into the TimerInit and TimerDiff functions, and I guess I could use those. The problem is that I need to do multiple such measurements continously, and I cannot figure out how I can do more than one simultanious time measurement using this function...

Can anyone show me a quick and dirty example of two measurements running side by side using either these functions, or some other more suitable function?

-Stigma

Link to comment
Share on other sites

multi threading is not possible, however with the suggestion /dev /null gave, you need to be careful of processor hunger.

Should not be a problem for my spesific app. If I can check the adlib every 500ms for example, that will be more than enough, and I don't expect that will drain that many cycles :) Besides I have a dualcore anyway.

-Stigma

Edited by stigma
Link to comment
Share on other sites

I need a function that allows me to measure how much real-time has passed from point A to point B in a script. I looked into the TimerInit and TimerDiff functions, and I guess I could use those. The problem is that I need to do multiple such measurements continously, and I cannot figure out how I can do more than one simultanious time measurement using this function...

Like this?

Dim $timer[5]

$timer[0] = TimerInit()
sleep(1000)
$timer[1] = TimerInit()
sleep(1000)
$timer[2] = TimerInit()
sleep(1000)

MsgBox(0,"First Timer",TimerDiff($timer[0]) & " " & TimerDiff($timer[1]) & " " & TimerDiff($timer[2]))
Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Now I just went and made a fool out of myself didn't I? *laughs*

Thats very logical, and I don't really know why I didn't just try different variables :)

Thanks a lot for the help tho. I should be all set for getting the basics of my script up and working :D

-Stigma

Link to comment
Share on other sites

see AdlibEnable()

This is amusing. I skipped right past AdlibEnable and AdlibDisable when I was looking for this type of functionality. "Why would I want to deal with a sound card? And why are they supporting such an antique, anyway?"

Glad I read this thread because I'm going to need exactly this type of thing before the end of the weekend.

Edited by RedSnertz
Link to comment
Share on other sites

I have a followup question - Is it not possible to have more than one adlib running at the same time?

When I run:

AdlibEnable("functionA")

AdlibEnable("functionB")

then is seems that it is only the one exeuted latest that is in effect. My suspicions are componded by the fact that it dosn't seem possible to turn off just one spesific Adlib, but instead the whole function is turned off...

Am I forced to have all Adlib functions gathered into one?

One more thing. Despite reading the documentation I was unable to set up the custom re-check timer on the adlib witouht getting syntaxt error. Perhaps im just stupid :/ but im still struggling a bit comming over to this syntaxt. if anyone has used it recently, give me an example?

Thanks :)

-Stigma

Link to comment
Share on other sites

  • Moderators

I have a followup question - Is it not possible to have more than one adlib running at the same time?

When I run:

AdlibEnable("functionA")

AdlibEnable("functionB")

then is seems that it is only the one exeuted latest that is in effect. My suspicions are componded by the fact that it dosn't seem possible to turn off just one spesific Adlib, but instead the whole function is turned off...

Am I forced to have all Adlib functions gathered into one?

One more thing. Despite reading the documentation I was unable to set up the custom re-check timer on the adlib witouht getting syntaxt error. Perhaps im just stupid :/ but im still struggling a bit comming over to this syntaxt. if anyone has used it recently, give me an example?

Thanks :)

-Stigma

You can only have one Adlib function run at a time, it should say that IMO.

I usually make my own AdlibManager()

AdlibEnable('_AdlibManager', 500)
Func _AdlibManager()
    AdlibDisable()
    _Function1()
    _Function2()
    AdlibEnable('_AdlibManager', 500)
    Return ''
EndFunc
You can really customize this with conditions, I'm just giving you the easy version :D.

Edit:

Added AdlibDisable() so your not tripping over yourself.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You can only have one Adlib function run at a time, it should say that IMO.

I usually make my own AdlibManager()

AdlibEnable('_AdlibManager', 500)
Func _AdlibManager()
    AdlibDisable()
    _Function1()
    _Function2()
    AdlibEnable('_AdlibManager', 500)
    Return ''
EndFunc
You can really customize this with conditions, I'm just giving you the easy version :D.

Edit:

Added AdlibDisable() so your not tripping over yourself.

From what I can determine here, this fixes the potential problem where the functions inside the adlib take longer to acomplish than the refresh of the adlib. Apart from that I don't quite see what else good this does. If I have missed something, please let me know :D

What I ended up doing was just heaping together all my adlib functions into the same adlib. It seems to work reasonably well, allthough there is no way to prioritize which adlib function should be given priority if more than one needs to be run. Its something I can live with and work around tho :)

-Stigma

Link to comment
Share on other sites

  • Moderators

From what I can determine here, this fixes the potential problem where the functions inside the adlib take longer to acomplish than the refresh of the adlib. Apart from that I don't quite see what else good this does. If I have missed something, please let me know :D

What I ended up doing was just heaping together all my adlib functions into the same adlib. It seems to work reasonably well, allthough there is no way to prioritize which adlib function should be given priority if more than one needs to be run. Its something I can live with and work around tho :)

-Stigma

Well I answered your question before I posted the code.

You can only have 1 adlib function running at a time. See the benefit now?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

another way is to fake the multi thread ability.

basically have your script call itself with various command line arguments. Then have a case statement at the start of the script that calls various functions depending on the command line passed.

This allows the same script to call itself to do various things without interrupting whats its doing. Now you have multiple scripts all doing various things but all the code is contained in just the one script.

If needed you can have have the various parts talk to each other in various methods. use ini files or the registry. I think StdIn/Out reading and writing would work as well but I've not tried that yet.

If you do a search for multi thread you will find lots of various methods to do this.

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...