Re: Someone changed my Thread Manager writeup?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Matt Lewis wrote:
> 
> Pete Lomax wrote:
> > 
> > 
> > Some other notes:
> > There should be a built-in single procedure call for:
> > }}}
<eucode>
> >       if CheckThread() then
> >         if QueryQuitMessage(0) then
> >         end if
> >         ContinueThread(TimeSlice)
> >       end if
> <font color="#330033">> </eucode>
{{{
</font></font>
> > rather than having to code the whole of that in every task loop.
> > 
> 
> I heartily agree.  That would make this library useful.  Here's how I'd
> make it platform/library agnostic:
> }}}
<eucode>
> -- The real QueryQuit() is a function, but this requires a
> -- procedure, so wrap the real thing here (users of other 
> -- libs may need to do the same):
> constant QUERYQUIT = routine_id("QueryQuitMessage")
> procedure query_quit_message()
>     if call_func( QUERYQUIT, {0}) then end if
> end procedure
> 
> integer event_rid
> sequence event_args
> 
> -- Set the default to use WinClass:
> event_rid = routine_id("query_quit_message")
> event_args = {}
> 
> -- You can make a procedure like this for any existing GUI lib
> -- to make it easy:
> global procedure useWin32Lib()
>     event_rid = routine_id("doEvents")
>     event_args = {0}
> end procedure
> 
> -- Users can specify their own routine if they like:
> global procedure useAny( integer rid, sequence args )
>     event_rid = rid
>     event_args = args
> end procedure
> 
> global procedure CheckThread()
>     if time() > EndSlice then
>         call_proc( event_rid, event_args )
>         EndSlice = time() + TimeSlice
>     end if
> end procedure
> <font color="#330033"></eucode>
{{{
</font>
> 
> Matt Lewis
> 

Hi Matt,

This is basically my 2nd generation of coding this technique, so
while there may be a way to wrap CheckThread() a little neater,
it's still easier to use than the old way i used to do it.
Besides, there is a little more to this then 'threads' alone...
QueryQuitMessage(0) is simply taking a break to check messages,
but QueryQuitMessage(1) allows the app to quit (tasks that dont
have to complete before the app quits).  If the caller uses
QueryQuitMessage(1) and they get a true return value then they 
should exit the loop.
I guess this could be coded as
  if CheckThread(1) then
    exit
  end if

which would make it a little neater i guess.



Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu