Threads and Stacks - PowerPoint PPT Presentation

About This Presentation
Title:

Threads and Stacks

Description:

Threads and Stacks Process: entire address space is private Threads: heap is common, but stack is private. What if stack wasn t private? DATA DATA – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 10
Provided by: Larry392
Category:
Tags: last | lectue | stacks | threads

less

Transcript and Presenter's Notes

Title: Threads and Stacks


1
Threads and Stacks
  • Process entire address space is private
  • Threads heap is common, but stack is private.
    What if stack wasnt private?

DATA
DATA
stack
stack
task 1 context
?
task 1 context
sp
globals
globals
sp
context swap
OS
OS
regs
regs
2
How TINY manages the stack
worst case stack size is sum of worst case for
each task, plus ISRs.
  • One stack/thread

stack 3
stack 3
stack 3
stack 2
stack 2
stack 1
stack 2
stack 1
stack 1
sp
sp
sp
globals
globals
globals
OS
OS
OS
regs
regs
regs
3
Reentrant Stack
re-stack 3
I dont know why the compiler doesnt use the
regular stack for re-entrant function calls! Prob
ably so that user can put re-entrant stack
into external data memory this is inefficient,
so limit use of re-entrant functions.
re-stack 2
re-stack 1
stack 3
re-sp
stack 2
stack 1
sp
globals
OS
regs
4
Is this safe (this is about parameter passing,
not stack stuff)
  • int function average(int a, int b, int c, int d,
    int e, int f)
  • return ((abcdef)/6)
  • void task1 _task_ 1 (void)
  • int a,b,c,d,e,f
  • disable()
  • average(a,b,c,d,e,f)
  • enable()
  • void task1 _task_ 1 (void)
  • int a,b,c,d,e,f
  • disable()
  • average(a,b,c,d,e,f)
  • enable()

5
Embedded System Types
  • Data flow dominated Systems
  • our music player
  • a network router
  • queues, messages, packets, routing
  • Control Dominated Systems
  • Software State machines, distributed state
    management/synchronization, e.g. power plant,
    autopilot, etc.

6
Design Meeting
  • Music Packet format TNE.CHAN,(CHAN0?OPCODETONE
    ),TONE,TONE
  • even if CHAN 0, TNE is valid. Thats why we
    cant use TNE field for OPCODE. TNE is not always
    31 when CHAN0.
  • From last week player has modes.
  • IDLE, all commands from the pilot are in the
    form of ASCII characters S and T?
  • STREAMINGall commands come in the form of music
    opcodes
  • OPCODE 0 means stop. This is a good choice
    because, if we set TNE 0, then okay if
    interpreted as TONE, we will start turning off
    the music anyway. So x.0,0 means stop. The
    player should send at least 0s to stop the
    player. Is it safe to set TNE 0? Check your
    software!! Stop means return to IDLE mode.
  • OPCODE 1 means CONTINUE, and TNE is valid
  • OPCODE 2 means PAUSE (was stop). Okay?? if we
    are paused how do we resume? What if we want to
    clear the buffer and start over? do we need more
    commands? Do we need to define a new mode? --
    PAUSED?
  • Do we need any other opcodes?
  • TRANSMITTING
  • How to we enter that mode?
  • what form do commands take? is PAUSE supported?
  • What is the format for a complete song?
  • What does the pilot send to the player to
    transmit a song?

7
Mode (State) Diagram for the Player
STREAM
IDLE
what is the difference between IDLE and PAUSED?
Modes are like states in an FSMbut they are not
static. What does that mean? There is an
execution sequence associated with each mode.
Mode determines response to events and choice
of next mode
Tx
PAUSED
8
An Alternative Is this equivalent?
S/clearb()
R
STREAM
IDLE
STOP
STOP
Tx
T/clearb()
9
Communication and Synchronization
  • Semaphores
  • Queues Messages, Mailboxes, and Pipes
  • Events
  • Rendezvous
Write a Comment
User Comments (0)
About PowerShow.com