Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Multi-tasking question

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
DH*
Guest





Posted: 19 July 2006, 18:19 PM    Post subject: Multi-tasking question Reply with quote

Assuming one main task and one secondary task, my understanding is that each task will get control at each RTC Tick which means each task gets about a 2mS time slice. My secondary task only needs about 1mS each time it is activated (by WaitForInterrupt). Instead of idling until the next RTC Tick, is there a way to return to the main task earlier without killing the secondary task?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 19 July 2006, 18:45 PM    Post subject: Reply with quote

Quote:
[...] is there a way to return to the main task earlier without killing the secondary task?

A call to Delay(0.0) will allow a task switch. Whether a task switch actually occurs depends on whether another task is ready/able to run.

As currently implemented, the next task to run will execute, at most, the remainder of the time slice unless, of course, it locks itself, etc. It might be better if the subsequently executing task got the remainder of the current time slice plus another whole time slice. The implemented behavior is the same as that of BasicX.
Back to top
DH*
Guest





Posted: 19 July 2006, 18:52 PM    Post subject: Reply with quote

dkinzer wrote:
It might be better if the subsequently executing task got the remainder of the current time slice plus another whole time slice.
That would be better.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 19 July 2006, 19:42 PM    Post subject: Reply with quote

I neglected to mention in my earlier reply that you can switch to a specific task using RunTask(). The desired task is indicated by passing its task control block array. For the Main() task, this is slightly more difficult because its task control block is not explictly defined. Rather, its task control block is located at the beginning of the remaining, unallocated RAM. The address of Main() task's task control block is available as Register.TaskMain. The CByteArray() conversion function needs to be used in conjunction with this in order to pass it to RunTask().
Code:
Call RunTask(CByteArray(Register.TaskMain))

Alternately, and more succinctly, you can switch to the Main() task by simply omitting the parameter:
Code:
Call RunTask()


Last edited by dkinzer on 20 July 2006, 0:50 AM; edited 1 time in total
Back to top
DH*
Guest





Posted: 19 July 2006, 21:34 PM    Post subject: Reply with quote

That helps code readability.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group