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
Another Task question

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





Posted: 15 May 2006, 13:37 PM    Post subject: Another Task question Reply with quote

All of the examples in the reference manual show the task stack being allocated at the module level before entering the Main task.

Whether or not my WaitForInterrupt task will be started depends on how the user configures the system. In some cases, there will be no need to start the task and, thus, no need to allocate its stack.

Is it possible to allocate the stack from within the Main task, in the routine that decides whether or not to start the task?
Back to top
dkinzer
Site Admin


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

Posted: 15 May 2006, 15:55 PM    Post subject: Reply with quote

Quote:
Is it possible to allocate the stack from within the Main task...


The task stack must be a module-level variable. The reason that this is so is that the task stack must have a lifetime that is at least as long as the task using it. The simplest way to guarantee that this requirement will be met is by requiring the use of a module-level variable.

An analysis of the source code might be able to determine if the lifetime of the task stack is long enough, e.g. if it can be determined that the routine containing the definitions never exits. On the other hand, I'm not convinced that the ability to do this would be beneficial in the situation that you described. The amount of stack space allocated for a procedure's local variables is the sum of the space required for the blocks of the path through the procedure that requires the most local variable space. The allocation happens once, at the beginning of the procedure. (If you're looking at the code, it is often done using the instruction ADDSP_B. It is sometimes done using DUP_B, DUP_W, DUP_D instructions when it is more efficient to do so.)

Consequently, the appearance of Dim ts(1 to 100) as Byte in a procedure guarantees that at least 100 bytes will be allocated for local variables (assuming that the block containing the definition is determined to be reachable).
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