1. Task scheduler sluggish

Here is a test case to show what I am doing:

without warning 
include win32lib.ew 
 
integer win, button1 
integer color 
atom taskthetask 
 
procedure thetask() 
while w32True do 
	setWindowBackColor( win, color ) 
	color = color + 20 
	task_yield() 
end while 
end procedure 
taskthetask = task_create(routine_id("thetask"),{}) 
 
procedure click1(integer self, integer event, sequence parms) 
	task_schedule(taskthetask,{0.1,0.3}) -- do every 200 ms 
end procedure 
 
procedure main() 
 
	color = 0 
 
    win = createEx(Window, "Test task schedule", 0, 0, 0, 400, 200, 0, 0) 
    button1 = createEx(Button, "start task", win, 0, 80, 90, 20, 0, 0) 
  
    setHandler(button1, w32HClick, routine_id("click1")) 
    WinMain(win, Normal) 
 
end procedure 
 
main() 

The problem is that it is very sluggish to run the task. But if I move the mouse around inside the window, the task works at its proper speed.

So, how do I get a task to run every 200 ms, whether or not someone is doing something else at the same time. And yes, I still want other stuff to go on if the user chooses.

Andy K.

new topic     » topic index » view message » categorize

2. Re: Task scheduler sluggish

penpal0andrew said...

Here is a test case to show what I am doing:

without warning 
include win32lib.ew 
 
integer win, button1 
integer color 
atom taskthetask 
 
procedure thetask() 
while w32True do 
	setWindowBackColor( win, color ) 
	color = color + 20 
	task_yield() 
end while 
end procedure 
taskthetask = task_create(routine_id("thetask"),{}) 
 
procedure click1(integer self, integer event, sequence parms) 
	task_schedule(taskthetask,{0.1,0.3}) -- do every 200 ms 
end procedure 
 
procedure main() 
 
	color = 0 
 
    win = createEx(Window, "Test task schedule", 0, 0, 0, 400, 200, 0, 0) 
    button1 = createEx(Button, "start task", win, 0, 80, 90, 20, 0, 0) 
  
    setHandler(button1, w32HClick, routine_id("click1")) 
    WinMain(win, Normal) 
 
end procedure 
 
main() 

The problem is that it is very sluggish to run the task. But if I move the mouse around inside the window, the task works at its proper speed.

So, how do I get a task to run every 200 ms, whether or not someone is doing something else at the same time. And yes, I still want other stuff to go on if the user chooses.

Andy K.

My experience with Euphoria tasks is limited so I won't suggest how best to use them. But I do see why you are having this problem. A typical Windows application spends most of it's time waiting for messages. While a thread is waiting for a message it can do nothing else. A Euphoria process has but one thread. Yes, Euphoria has tasks but they are implemented within the interpreter and the system knows nothing of them.

While the single euphoria thread is waiting for a message it can do nothing else, and that means that Euphoria's task sheduler isn't even running. There is no way it can call your thread. When you move the mouse or press a key it becomes active again and the scheduler is able to run again.

I don't think that Euphoria threads are a good fit here. If or when Euphoria has real threads this will be possible. Until then you will need to find another way. One way would be to use a timer that sends a message every 200ms.

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

3. Re: Task scheduler sluggish

LarryMiller said...

The problem is that it is very sluggish to run the task. But if I move the mouse around inside the window, the task works at its proper speed.

So, how do I get a task to run every 200 ms, whether or not someone is doing something else at the same time. And yes, I still want other stuff to go on if the user chooses.

Andy K.

My experience with Euphoria tasks is limited so I won't suggest how best to use them. But I do see why you are having this problem. A typical Windows application spends most of it's time waiting for messages. While a thread is waiting for a message it can do nothing else. A Euphoria process has but one thread. Yes, Euphoria has tasks but they are implemented within the interpreter and the system knows nothing of them.

While the single euphoria thread is waiting for a message it can do nothing else, and that means that Euphoria's task sheduler isn't even running. There is no way it can call your thread. When you move the mouse or press a key it becomes active again and the scheduler is able to run again.

I don't think that Euphoria threads are a good fit here. If or when Euphoria has real threads this will be possible. Until then you will need to find another way. One way would be to use a timer that sends a message every 200ms.

[/quote]

Yes. I am now using the setTimer, onTimer event and it is working.

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

4. Re: Task scheduler sluggish

penpal0andrew said...

So, how do I get a task to run every 200 ms, whether or not someone is doing something else at the same time. And yes, I still want other stuff to go on if the user chooses.

I see that this has been answered already so I'll just add that in Windows use the Windows timer or Windows threads and do not use Euphoria's tasks, as they are really meant for console applications and not GUI applications.

One day, I hope that Euphoria will be able to use the operating systems's threads/tasks directly but that will have to wait for a bit longer yet.

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

5. Re: Task scheduler sluggish

Win32lib has to be modified to be compatible with multitasking. I'm confused about the current condition of win32lib since everything is in a state of flux until 4.0 is released. I remember having problems about a year ago and I got it to work by inserting some task_yield() statements in win32lib.ew. I have no idea if that is now included in the latest release of win32lib. Does anyone know?

I have win32lib.ew (version 0.60.6) with task_yield() inserted in 3 places. I don't remember if it came that way or if I modified my copy...I haven't used it for a while, but it seems to work properly.

Around line 33393:

procedure eventLoop(object pData) 
    sequence temp 
    atom msg 
    atom getRC 
    integer inc 
    integer el 
    integer lTock 
 
    ActiveEL &= 0 
    el = length(ActiveEL) 
 
    -- Allocate a message buffer 
    msg = w32acquire_mem(0, SIZEOF_MSG) 
    lTock = 0 
    -- message loop 
    while ActiveEL[el] = 0 
      and vWinMainState = kStarted do 
 
        if vIdleCheck then 
            while w32Func(xGetQueueStatus, {QS_ALLEVENTS}) = 0 do 
                lTock += 1 
                if sequence(invokeHandler(Screen, w32HIdle, {lTock, msg})) then 
                    -- The user wishes to stop being idle and instead 
                    -- use the data they have loaded into the msg structure. 
                    lTock = -2 
                    exit 
                end if 
                 
                task_yield() --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
            end while 
 
            if lTock >= 0 then 
 
                getRC = w32Func( xPeekMessage, { msg, 0, 0, 0, PM_REMOVE } ) 
                if getRC > 0 and peek4u(msg+4) = WM_QUIT then 
                    exit 
                end if 
                -- I've decided to ignore the undocumented windows message WM_SYSTIMER ('280') 
                -- so it won't stop the idling tock counting. 
                if lTock > 0 and peek4u(msg+4) != WM_SYSTIMER then 
                    -- Signal end of idleness period. 
                    VOID = invokeHandler(Screen, w32HIdle, {-1, msg}) 
                    lTock = 0 
                end if 
            else 
                lTock = 0 
            end if 
 
        else 
            getRC = w32Func( xGetMessage, { msg, 0, 0, 0 } ) 
            if  getRC = 0 
             or getRC = -1 then 
                exit 
            end if 
        end if 
 
        -- Gather some entropy for the random integer routine 
        w32Seed = remainder((w32Seed * peek4u(msg+16)) 
                            + 1 + peek4u(msg+20) * peek4u(msg+24), 
                            #FFFFFFFF) 
 
        w32Proc( xTranslateMessage, { msg } ) 
        w32Proc( xDispatchMessage, { msg } ) 
         
        task_yield() --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
         
    end while 

And around line 33482:

global procedure doEvents(integer id) 
    atom msg, hWnd 
 
    if vWinMainState != kStarted then 
    return 
    end if 
 
    if id = 0 then 
    hWnd = 0 
    else 
    if validId(id) = w32False then 
        return 
    end if 
    hWnd = getHandle(id) 
    end if 
 
    -- Allocate a message buffer 
    msg = w32acquire_mem(0, SIZEOF_MSG) 
 
    if w32Func( xPeekMessage, { msg, hWnd, 0, 0, PM_REMOVE } ) then 
        w32Proc( xTranslateMessage, { msg } ) 
        w32Proc( xDispatchMessage, { msg } ) 
    end if 
    w32release_mem(msg) 
     
    task_yield() --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
     
end procedure 
r_doEvents = routine_id("doEvents") 
new topic     » goto parent     » topic index » view message » categorize

6. Re: Task scheduler sluggish

ryanj said...

Win32lib has to be modified to be compatible with multitasking. I'm confused about the current condition of win32lib since everything is in a state of flux until 4.0 is released.

The current one at SourceForge has 2 of those task_yields() in it. It has not got the one that fires during the "idle" loop. I'll add that one in now.

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

7. Re: Task scheduler sluggish

DerekParnell said...
ryanj said...

Win32lib has to be modified to be compatible with multitasking. I'm confused about the current condition of win32lib since everything is in a state of flux until 4.0 is released.

The current one at SourceForge has 2 of those task_yields() in it. It has not got the one that fires during the "idle" loop. I'll add that one in now.

Uploaded as SVN#61

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

8. Re: Task scheduler sluggish

DerekParnell said...
DerekParnell said...
ryanj said...

Win32lib has to be modified to be compatible with multitasking. I'm confused about the current condition of win32lib since everything is in a state of flux until 4.0 is released.

The current one at SourceForge has 2 of those task_yields() in it. It has not got the one that fires during the "idle" loop. I'll add that one in now.

Uploaded as SVN#61

Thanks, DerekP. I should update to the latest win32lib...

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

Search



Quick Links

User menu

Not signed in.

Misc Menu