Log in

View Full Version : Sleep vs wait



[Nathan]
01-05-2012, 04:23 AM
Is there a difference?

cause
01-05-2012, 04:24 AM
good question!

[Nathan]
01-05-2012, 04:27 AM
I see that most people use wait, but I've always used sleep since thats what most java bots used and is what I've been used to.

Brandon
01-05-2012, 04:35 AM
Sleep is what you would call I guess Permanent.. You cannot wake up something sleeping sorta like a thread..
Wait should be used when doing conditions..

Example:

Thread.Wait(1000);..... It will still be using up cpu.. whereas Sleep will make it totally shut off and can only be turned back on when you call it again.. Sleep is usually called when you just want the process to sleep/sorta stop.. usually at the end of a thread's procedure.. Whereas wait can be called anywhere to sorta pause for a length of time and then continue on..

Wait = woken up by notify..
Sleep = Interupted.. never awaken.

Kinda hard to explain.. oh gosh I hope someone who is better at teaching can elaborate more/better..

My general rule is wait for objects/conditions.. sleep for threads and stuff that I don't want to be woken up.

[Nathan]
01-05-2012, 04:36 AM
Sleep is what you would call I guess Permanent.. You cannot wake up something sleeping sorta like a thread..
Wait should be used when doing conditions..

Example:

Thread.Wait(1000);..... It will still be using up cpu.. whereas Sleep will make it totally shut off and can only be turned back on when you call it again..

Wait = woken up by notify..
Sleep = Interupted.. never awaken.

Kinda hard to explain.. oh gosh I hope someone who is better at teaching can elaborate more/better..
I understand what you mean I think, but when should you use one vs the other then?

Brandon
01-05-2012, 04:38 AM
;882552']I understand what you mean I think, but when should you use one vs the other then?

Sleep for threads and processes, wait for objects/conditions/timers.. That's my general rule for it.. I can't explain very well at all because in C++, I don't think there is a wait proc.. its just Sleep(1000); and it pauses.. but for threads when you call Thread.Sleep.. thats a different one, it doesn't continue after the sleep.

I'll do some digging around and get back to this and see if there are better explanations.. maybe wizzup, benland, narcle or nava or someone can explain.

best explanation I can find in SIMPLE terms.. http://www.differencebetween.net/technology/software-technology/difference-between-sleep-and-wait/

ShawnjohnSJ
01-05-2012, 04:39 AM
In java, Thread.sleep() is used to sleep for a specific amount of time without being woken up by another Thread. wait() sleeps for a specific amount of time, but it can be woken up by another thread by using notify(). Although I'm not sure if theres much of a difference in SCAR/Simba, it may just be a wrapper function.

[Nathan]
01-05-2012, 04:43 AM
In java, Thread.sleep() is used to sleep for a specific amount of time without being woken up by another Thread. wait() sleeps for a specific amount of time, but it can be woken up by another thread by using notify(). Although I'm not sure if theres much of a difference in SCAR/Simba, it may just be a wrapper function.
Thats why I was initially confused because I'm used to java, but there isn't multithreading possible with simba, so I didn't know why there would be a difference.

Brandon
01-05-2012, 04:58 AM
;882561']Thats why I was initially confused because I'm used to java, but there isn't multithreading possible with simba, so I didn't know why there would be a difference.

Could possibly be the internals.. Simba has some threads in it..

TM.Thread.. PSThread.. etc.. And I THINK you can thread in simba it's just a stupid way of doing it because you cannot access variables.. the idea is the create the thread in a plugin/dll and call it in a script -__-

Anyway I'm sure the Sleep vs Wait won't affect any scripts so I guess it's safe to use either one..

[Nathan]
01-05-2012, 05:00 AM
Could possibly be the internals.. Simba has some threads in it..

TM.Thread.. PSThread.. etc.. And I THINK you can thread in simba it's just a stupid way of doing it because you cannot access variables.. the idea is the create the thread in a plugin/dll and call it in a script -__-

Anyway I'm sure the Sleep vs Wait won't affect any scripts so I guess it's safe to use either one..

True, but not being able to access variables and having to make a plugin for it makes threading in simba pretty much useless... Which isn't a huge problem, most things can be done without threads, it makes some things better, but its six of one half a dozen of the other in most cases.