The
Questions tagged [ucontext]
64 questions
12
votes
1 answer
What does the getcontext system call (ucontext.h) really do?
I took operating systems last year, during which I used user contexts (defined in the header ucontext.h) to implement a thread scheduler (in which each thread simulated a process) for a project. I'm taking part in a lecture and will talk about user…

kibibyte
- 3,007
- 5
- 30
- 40
10
votes
1 answer
Ucontext in linux
I read that ucontext is used to save context between multiple threads in linux. Since the OS does the context switching between different threads, why does linux provide this header file (ucontext.h) for context switching?

Embedded Programmer
- 519
- 4
- 8
- 22
9
votes
1 answer
Are the makecontext()/swapcontext() functions compatible with C++
In unix environments the makecontext()/swapcontext() family of functions is sometimes used to implement coroutines in C. However these functions directly manipulate the stack and the execution flow. Often when these low level functionalities are…

LiKao
- 10,408
- 6
- 53
- 91
9
votes
2 answers
valgrind error and ucontext. Why "Use of uninitialised value of size 8"?
I have been trying to understand why valgrind complains about "Use of uninitialised value of size 8" for this small test program that uses ucontexts.
It is basically a program that creates "n_ucs" ucontexts and switches over them for "max_switch"…

jackquiver
- 91
- 2
- 3
7
votes
1 answer
Using the third parameter (void* context) of a sigaction handler with SIG_INFO results in a Segmentation Fault
I have reduced a huge fiber scheduler code that was producing the problem to the lines below.
What I expect is a clean return to the context, passed to the handler, every time.
What I get is "Handler. " printed out three times and then a…

John Locke
- 153
- 1
- 9
6
votes
1 answer
User-threaded scheduling API on mac OSX using ucontext & signals
I'm designing a scheduling algorithm that has the following features:
Have 2 user-threads (contexts) in the one process (I'm supposed to do 3 threads but that didn't work on osx yet, so I decided to make 2 work for now)
preemptive using a SIGALRM…

JJ Adams
- 481
- 4
- 17
6
votes
1 answer
switching up/down the stack with getcontext/setcontext
I am trying to understand if getcontext/setcontext will work correctly in a specific scenario.
I can see how setcontext() can be used to unwind the stack back to a certain place in history.
#include
#include
int rollback =…

Martin York
- 257,169
- 86
- 333
- 562
4
votes
1 answer
Reading SSE registers (XMM, YMM) in a signal handler
I have an x86_64 instruction "vgatherqpd %ymm7,(%r9,%ymm1,8),%ymm3" for which I need to construct the memory address at runtime in a signal handler in Linux. The signal handler ucontext uc_mcontext.gregs[XED_REG_R9] gives me the value contained in…

user1205476
- 391
- 1
- 3
- 12
4
votes
1 answer
Context switching - Is makecontext and swapcontext working here (OSX)
I'm having some fun with context switching. I've copied the example code into a file
http://pubs.opengroup.org/onlinepubs/009695399/functions/makecontext.html
and i defined the macro _XOPEN_SOURCE for OSX.
#define _XOPEN_SOURCE
#include…

friartuck
- 2,954
- 4
- 33
- 67
4
votes
1 answer
Linux context switch internals: What happens when process exits before timer interrupt?
How is context switch made in linux kernel when process exits before timer interrupt?
I know that if the process is running and timer interrupt occurs then schedule function is called automatically if the flag is set, schedule function then selects…

Nullpointer
- 1,086
- 7
- 20
4
votes
1 answer
Why does ucontext have such high overhead?
The documentation for Boost.Context in Boost v1.59 reports the following performance comparison results:
+----------+----------------------+-------------------+-------------------+----------------+
| Platform | ucontext_t | fcontext_t …

DaoWen
- 32,589
- 6
- 74
- 101
4
votes
1 answer
Context switching - ucontext_t and makecontext()
I am studying context switching in C programming and have found the following example code on the Internet. I am trying to figure out whether only makecontext() function can trigger a function that does something. The other functions such as…

TonyW
- 18,375
- 42
- 110
- 183
4
votes
2 answers
Is the type `stack_t` no longer defined on linux?
The linux platform is Ubuntu 12.04
I have the following headers included in my source code:
#include
#include
#include
...
When I compile it however, it complains…

Jimmy Lu
- 4,810
- 7
- 25
- 30
3
votes
0 answers
is it safe to have two lua thread run parallel on the same lua state without concurrent execution?
we are developing game server using lua.
the server is single threaded, we'll call lua from c++.
every c++ service will create a lua thread from a global lua state which is shared by all service.
the lua script executed by lua thread will call a c…

kevin adam
- 33
- 4
3
votes
1 answer
Why was ucontext added to and then removed from POSIX?
As far as I know, ucontext offers something better then setjmp. But it's deprecated and now removed from the POSIX spec. So why did it appear and why was it removed?

eonil
- 83,476
- 81
- 317
- 516