Solution two two threads sharing a cpu concept

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: es or other heap data are shared Problem? Solution? Two Two Threads Sharing a CPU concept reality context switch A Peek Inside a Running Program Peek CPU common runtime x your program code library R0 Rn your data PC SP x y heap registers y stack “memory” A Program With Two Threads Program ready to run x running Your program code library R0 Rn your data PC SP x y registers y stack stack “memory” Thread Thread Context Switch switch switch out in x your program code library R0 Rn 1. save registers PC SP your data x y registers y stack 2. load registers stack “memory” I want to see the code … want You asked for it (MIPS): /* Symbolic register names */ #define z $0 /* zero register */ #define a0 $4 /* argument registers */ #define a1 $5 #define s0 $16 /* callee saved */ #define s1 $17 #define s2 $18 #define s3 $19 #define s4 $20 #define s5 $21 #define s6 $22 #define s7 $23 #define sp $29 /* stack pointer */ #define fp $30 /* frame pointer */ #define ra $31 /* return address */ SWITCH: sw sp, SP(a0) # save new stack pointer sw s0, S0(a0) # save all the callee-save registers sw s1, S1(a0) sw s2, S2(a0) sw s3, S3(a0) … sw s7, S7(a0) sw fp, FP(a0) sw ra, PC(a0) # save return address lw sp, SP(a1) # load the new stack pointer lw s0, S0(a1) # load the callee-save registers lw s1, S1(a1) lw s2, S2(a1) # save frame pointer … lw fp, FP(a1) lw ra, PC(a1) j ra .end S...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online