5

Is a POSIX context switch well-defined? Is it the same thing as switching threads in C? Can the C compiler generate everything for a context switch or is assembly programming still needed for a routine that switches the threads or switches the "context"? Is there even defined what is meant by "context" - isn't it the same as a thread?

3

POSIX uses the term context switch for at least two different purposes, without attempting to define it rigorously (or even providing a definition):

  • switching between threads, and
  • switching between processes

Rather, POSIX assumes you already know what the term means. For instance,

3.118 CPU Time (Execution Time)

The time spent executing a process or thread, including the time spent executing system services on behalf of that process or thread. If the Threads option is supported, then the value of the CPU-time clock for a process is implementation-defined. With this definition the sum of all the execution times of all the threads in a process might not equal the process execution time, even in a single-threaded process, because implementations may differ in how they account for time during context switches or for other reasons.

Further reading:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.