AlanSTACK
AlanSTACK

Reputation: 6065

Where is the program counter stored during thread context switch?

When I call pthread_yield or pthread_block and the CPU does a context switch

Is the program counter stored in the thread stack (alongside its temporary registers) or in the thread control block (alongside the stack pointer)

Upvotes: 1

Views: 2617

Answers (2)

MichaelGL
MichaelGL

Reputation: 61

Quoting from VxWorks:APPLICATION PROGRAMMER’S GUIDE,page 76:

Each task has its own context, which is the CPU environment and system resources that the task sees each time it is scheduled to run by the kernel. On a context switch, a task’s context is saved in the task control block(TCB).

A task’s context includes:

■a thread of execution; that is, the task’s program counter

■the tasks’ virtual memory context (if process support is included)

■the CPU registers and (optionally) coprocessor registers stacks for dynamic variables and function calls

■I/O assignments for standard input, output, and error

■a delay timer

■a time-slice timer

■kernel control structures

■signal handlers

■task variables

■error status (errno)

■debugging and performance monitoring values

Upvotes: 0

aneesh jose
aneesh jose

Reputation: 381

Usually it shall be in the TCB. But I beleive it is implementation specific. An example of information contained within a TCB is:

  • Thread Identifier:Unique id (tid) is assigned to every new thread
  • Stack pointer: Points to thread's stack in the process
  • Program counter
  • State of the thread (running, ready, waiting, start, done)
  • Thread's register values
  • Pointer to the Process control block (PCB) of the process that the thread lives on

Upvotes: 4

Related Questions