Hi Elvin, It might be a bit easier to understand with the comments left in:
if (old_tcb != new_tcb) { /* Set the new currently-running thread pointer */ curr_tcb = new_tcb; /* Call the architecture-specific context switch */ archContextSwitch (old_tcb, new_tcb); } /** * The context switch shifted execution to a different thread. By the time * we get back here, we are running in old_tcb context again. Clear its * suspend status now that we're back. */ old_tcb->suspended = FALSE; The suspended flag is set to TRUE when a thread is being suspended, and is set to FALSE when it runs again. This is used as housekeeping, to keep a track of what suspension state a thread is in. For any thread that calls into this function, the calling thread (itself) is old_tcb and the new thread being switched in is new_tcb. When you return from archContextSwitch() *in the context of the original calling thread* then the running thread is back to the original thread (old_tcb), so it needs to mark itself as not suspended any more, by setting its flag to FALSE again. Thanks, Kelvin. On 11 September 2012 12:29, elvinwds <elvin...@gmail.com> wrote: > Hi All: > > I am a new to RTOS and have been studying the source code of atomthreads > for a while, and now I have question about the atomThreadSwitch function in > atomkernel.c. > > The source code without comments of atomThreadSwitch is : > static void atomThreadSwitch(ATOM_TCB *old_tcb, ATOM_TCB *new_tcb) > { > if (old_tcb != new_tcb) > { > /* Set the new currently-running thread pointer */ > curr_tcb = new_tcb; > > /* Call the architecture-specific context switch */ > archContextSwitch (old_tcb, new_tcb); > } > > old_tcb->suspended = FALSE; > > } > > My question is about the last line : "old_tcb->suspended = FALSE". Only > when the old thread been scheduled back in, the RTOS can run to here. This > means that when the RTOS runs to here , the old thread has been scheduled > out, so the state of the old thread can not be suspended, And why have to > set the state of suspended false here? > > > With Regards, > Elvin