1. sleep()

hey all,

The help file doesn't say sleep(0) is valid, or what it would do, so i put
together a small
program to check it out...

----------------------------------------------
include get.e
include misc.e

object key, wastetime
wastetime = 0

puts(1,"t= "&sprintf("%d",time())&"\n")

for loop = 1 to 10000000 do
 wastetime += 1
end for

puts(1,"t= "&sprintf("%d",time())&"\n")

for loop = 1 to 10000000 do
 --sleep(0)
end for

puts(1,"t= "&sprintf("%d",time())&"\n")

for loop = 1 to 10000000 do
 sleep(0)
end for

puts(1,"t= "&sprintf("%d",time())&"\n")

key = wait_key()
abort(0)
------------------------------------

which prints out:

t= 0 -- init the time()
t= 1 -- the inc of wastetime takes a sec
t= 2 -- doing nothing 10,000,000 times takes a sec too
t= 10 -- sleeping(0) 10,000,000 times takes 8 secs

So am i correct in assuming that sleep(0) tells windose's task manager to jump
tasks,
to let the next application in it's list run, but without a *timed* sleep
applied to the Eu
program? If this is what is happening, shouldn't this be in the help files? 

Or is the overhead in the sleep(0) call taking the 8 secs, and windose is not
telling the
task manager to go do something else? If this is the case, Robert, can you make
it tell
the OS to goto the next task without a timed sleep, rather like the cooperative 
timesliced multitasking in win3.1?

Kat

new topic     » topic index » view message » categorize

2. Re: sleep()

Kat writes:

> The help file doesn't say sleep(0) is valid, or what it would do

Sorry, my WATCOM manual doesn't say what sleep(0) will do.
If it's calling the WIN32 API sleep(), then another task might
be scheduled at this point.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

3. sleep()

Someone tell someone else that sleep(0) returns the cpu to the OS 
(windoze) without setting a timer, and the OS can indeed run the next 
application? It's a holdover from win3.x programming, wherein the app had to 
relinquish the cpu for the task scheduler to run the next app.

Kat

new topic     » goto parent     » topic index » view message » categorize

4. Re: sleep()

On Fri, 13 Jun 2003 01:13:59 -0500, <gertie at visionsix.com> wrote:

>
>
> Someone tell someone else that sleep(0) returns the cpu to the OS 
> (windoze) without setting a timer, and the OS can indeed run the next 
> application? It's a holdover from win3.x programming, wherein the app had 
> to relinquish the cpu for the task scheduler to run the next app.
>
To quote the Microsoft SDK...



Sleep
The Sleep function suspends the execution of the current thread for at 
least the specified interval.


VOID Sleep(
  DWORD dwMilliseconds   // sleep time
);
Parameters
dwMilliseconds [in] Specifies the minimum time interval, in milliseconds, 
for which execution is to be suspended. 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.

Return Values
This function does not return a value.

Remarks
This function causes a thread to relinquish the remainder of its time slice 
and become unrunnable for at least the specified number of milliseconds, 
after which the thread is ready to run. In particular, if you specify zero 
milliseconds, the thread will relinquish the remainder of its time slice 
but remain ready. Note that a ready thread is not guaranteed to run 
immediately. Consequently, the thread may not run until some time after the 
specified interval elapses. For more information, see Scheduling 
Priorities.


-- 

cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

5. Re: sleep()

On 13 Jun 2003, at 16:23, Derek Parnell wrote:

> 
> 
> On Fri, 13 Jun 2003 01:13:59 -0500, <gertie at visionsix.com> wrote:
> 
> >
> > Someone tell someone else that sleep(0) returns the cpu to the OS 
> > (windoze) without setting a timer, and the OS can indeed run the next 
> > application? It's a holdover from win3.x programming, wherein the app had to
> > relinquish the cpu for the task scheduler to run the next app.
> >
> To quote the Microsoft SDK...
> 
> 
> Sleep
> The Sleep function suspends the execution of the current thread for at 
> least the specified interval.
> 
> 
> VOID Sleep(
>   DWORD dwMilliseconds   // sleep time
> );
> Parameters
> dwMilliseconds [in] Specifies the minimum time interval, in milliseconds, 
> for which execution is to be suspended. 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.
> 
> Return Values
> This function does not return a value.
> 
> Remarks
> This function causes a thread to relinquish the remainder of its time slice
> and
> become unrunnable for at least the specified number of milliseconds, after
> which
> the thread is ready to run. In particular, if you specify zero milliseconds,
> the
> thread will relinquish the remainder of its time slice but remain ready. Note
> that a ready thread is not guaranteed to run immediately. Consequently, the
> thread may not run until some time after the specified interval elapses. For
> more information, see Scheduling Priorities.

Thanks muchly, Derek!

To who questioned me:  tongue

Kat

new topic     » goto parent     » topic index » view message » categorize

6. Re: sleep()

Kat:

If a thread relinquishs the remainder of its time slice to any other thread,
and you are not capable of using threads in Euphoria; then why are using
the sleep() ??

Bernie

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu