Questions tagged [context-switch]

A context switch is the process of storing and restoring the state (context) of a process.

In computing, a context switch is the process of storing and restoring the state (context) of a process so that execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU and is an essential feature of a multitasking operating system. What constitutes the context is determined by the processor and the operating system.

313 questions
0
votes
1 answer

Seg fault when returning to function execution after successful swapcontext

I'm trying to write a library to manage threads using contexts(getcontext, setcontext, makecontext, swapcontext), without pthreads. A function MyThreadYield(), pauses the current thread context, sends it to the end of ready queue and starts…
0
votes
1 answer

How does a switch from a thread's user mode stack to kernel stack occur without losing the original stack pointer?

After reading this question on how context switches occur, I am still a little confused as to how exactly the switch is made from a thread's user mode stack to its kernel stack. I would assume this would mean changing the value of the stack pointer…
mclaassen
  • 5,018
  • 4
  • 30
  • 52
0
votes
2 answers

How to save the state(context) of multiple functions in a program

We are trying to switch between multiple functions in our C program after saving the state using setjmp and longjmp but for only one function we are able to save the context not for other two functions. What could be the possible solution to it.…
Kush
  • 1
0
votes
1 answer

How to guarantee that the API returns before its callback is invoked in asyncronous API (c++)

I develop a library which has asyncronous APIs. One of the APIs, when it is called, it creates a task, pushs it to task thread and returns its task ID. After the task is completed, task thread notify the result to caller by invoking a callback…
sskim
  • 3
  • 2
0
votes
1 answer

MSP430 execution banks

I am new to MSP430 architecture and I am porting an RTOS which is written for ARM Cortex M3 into this architecure. In ARM Cortex architecture, there are PSP and MSP registers to hold stack values for execution modes. As I understand from MSP430…
albin
  • 773
  • 1
  • 8
  • 27
0
votes
0 answers

determine context switch and copys within a range in my programm (C++) - debian

i want to determine the count of context switches and the copys that are needed for context switches within a range in my programm for e.g. (code line 100 - 300). how can i do this? i tried setting up lttng but i dont know how to read traces. The…
Dogan
  • 181
  • 2
  • 7
0
votes
1 answer

Linux - reasons for preemption

I want to update the kernel to do some more stuff when switching between tasks and for that i need to find the reason for each switch. First, i can't find the function where schedule() is called when there is a higher priority task than the current…
juliarak
  • 1
  • 1
0
votes
1 answer

number of cores effecting multithreading OS

I'm trying to determine something regarding the way that my PC works, I have a dual core PC, and I'm trying to test it with a code I wrote, The program multiplies two matrices using threads (in java) when every thread handles matrix rows divided…
0
votes
1 answer

function-like behavior without any callstack use

I am working with a small cooperative OS (Salvo), in C, for an embedded target (MSP430). I have to implement a command handler with a large number of non-reusable implementation codes. Those codes may include context switches, using the OS. During a…
pserra
  • 206
  • 1
  • 11
0
votes
1 answer

switch context in C

I am learning how to use ucontext_t in C, and have written the following code. I wish to use an infinite while loop to watch the switching between two contexts (ctx_main, and ctx_thread). But, the context seems to be stuck in the while loop. I am…
TonyW
  • 18,375
  • 42
  • 110
  • 183
0
votes
3 answers

How can I discover how long does it take to do a context switch on my operating system?

I'd like to know how long does it take a context switch on my operating system. Is there a hack to do this? Can I do it with Java or I will need native code (eg. in C)? Does context switch differ for different threads?
Johnny
  • 1,509
  • 5
  • 25
  • 38
0
votes
5 answers

C++ context switch and mutex problem

Ok.. here is some background on the issue. I have some 'critical' code that i'm trying to protect with a mutex. It goes something like this Mutex.Lock() // critical code // some file IO Mutex.Unlock(). Now the issue is that my program seems to be…
shergill
  • 3,738
  • 10
  • 41
  • 50
0
votes
2 answers

How to synchronize two tasks with Micro C OS II?

I have this specification: task 0 sends integer numbers (starting from 1) to task 1. Task 1 shall multiply the numbers with -1 and send them back to task 0. Task 0 shall then print these numbers to the console. For the communication between…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0
votes
1 answer

Why must ContextSwitch be atomic and how to achieve this in practice?

Why must ContextSwitch be atomic and how to achieve this in practice? I think it must be atomic because if it doesn't save the state of previous processes completely, it can cause problems for future contextSwitches.Inaccuracy, and wrong data. And…
0
votes
3 answers

Context Switch questions: What part of the OS is involved in managing the Context Switch?

I was asked to anwer these questions about the OS context switch, the question is pretty tricky and I cannot find any answer in my textbook: How many PCBs exist in a system at a particular time? What are two situations that could cause a Context…
1 2 3
20
21