DH* Guest
|
|
Posted: 15 May 2006, 13:37 PM Post subject: Another Task question |
|
|
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? |
|
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 15 May 2006, 15:55 PM Post subject: |
|
|
| 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). |
|