ucontext

How to pass ellipsis argument to makecontext, which also accepts ellipsis argument in C?

喜你入骨 提交于 2021-01-29 09:32:06
问题 I have a function that runs other functions, and these functions can have a variable number of arguments. The parameter of this function is then passed to makecontext , which attaches the function to a ucontext_t structure, but the problem is this function also takes variable number of arguments. So my question is, how do I pass ellipsis argument obtained from a function to makecontext given that I can't change makecontext ? void run_function(void (*func), int argc, ...) { va_list vl; va

Is the type `stack_t` no longer defined on linux?

十年热恋 提交于 2019-12-20 01:03:48
问题 The linux platform is Ubuntu 12.04 I have the following headers included in my source code: #include <unistd.h> #include <signal.h> #include <ucontext.h> ... When I compile it however, it complains /usr/include/x86_64-linux-gnu/sys/ucontext.h:139:5: error: unknown type name 'stack_t' I googled and found that stack_t should be defined in signal.h , but here it doesn't seem to be defined? 回答1: This is meant to be a comment but I cannot make it readable there. Sorry. Did you #define one of the

warning: ‘noreturn’ function does return

南楼画角 提交于 2019-12-13 05:47:20
问题 I'm doing a thread library (changing context with uncontext.h). My function is of type void, and I can't return. But even if I do not return, this warning appears when compiling: dccthread.c: In function ‘dccthread_init’: dccthread.c:184:1: warning: ‘noreturn’ function does return [enabled by default] } This is a simplified code of the function (without some details): void dccthread_init(void (*func), int param) { int i=0; if (gerente==NULL) gerente = (dccthread_t *) malloc(sizeof(dccthread_t

Switching Thread Contexts with SIGALRM

北城余情 提交于 2019-12-12 03:56:00
问题 I have a problem. I need to implement a program that switches ucontext threads using a timer and SIGALRM but I am getting a segmentation fault when I switch threads using my evict_thread function. I believe it is the result of a race condition as it occurs at different times durings the programs execution. Here is my evict_thread void evict_thread(int signal) { // Check that there is more than one thread in the queue if ((int)list_length(runqueue) > 1) { // Remove the currently executing

switching up/down the stack with getcontext/setcontext

馋奶兔 提交于 2019-12-07 02:56:33
问题 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 <stdio.h> #include <ucontext.h> int rollback = 0; ucontext_t context; void func(void) { setcontext(cp); } int main(void) { getcontext(&context); if (rollback == 0) { printf("getcontext has been called\n"); rollback++; func(); } else { printf("setcontext has been called\n"); } } But I was wondering

Why does ucontext have such high overhead?

寵の児 提交于 2019-12-06 11:14:00
问题 The documentation for Boost.Context in Boost v1.59 reports the following performance comparison results: +----------+----------------------+-------------------+-------------------+----------------+ | Platform | ucontext_t | fcontext_t | execution_context | windows fibers | +----------+----------------------+-------------------+-------------------+----------------+ | i386 | 708 ns / 754 cycles | 37 ns / 37 cycles | ns / cycles | ns / cycles | | x86_64 | 547 ns / 1433 cycles | 8 ns / 23 cycles

Ucontext in linux

大憨熊 提交于 2019-12-06 07:43:28
问题 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? 回答1: ucontext.h defines functions (setcontext, getcontext, makecontext, and swapcontext) and structures ( ucontext_t and mcontext_t ) that allow the programmer to save and restore the program context. Using these functions, a programmer can implement advanced flow control

valgrind error and ucontext. Why “Use of uninitialised value of size 8”?

被刻印的时光 ゝ 提交于 2019-12-04 20:39:58
问题 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" times. I understand the "Warning: client switching stacks?" (which is basically what the program all about), but I can't really make sense to all the "Use of uninitialised value of size 8" I would like to get some help understanding if Valgrind

Why does ucontext have such high overhead?

青春壹個敷衍的年華 提交于 2019-12-04 16:33:37
The documentation for Boost.Context in Boost v1.59 reports the following performance comparison results: +----------+----------------------+-------------------+-------------------+----------------+ | Platform | ucontext_t | fcontext_t | execution_context | windows fibers | +----------+----------------------+-------------------+-------------------+----------------+ | i386 | 708 ns / 754 cycles | 37 ns / 37 cycles | ns / cycles | ns / cycles | | x86_64 | 547 ns / 1433 cycles | 8 ns / 23 cycles | 16 ns / 46 cycles | ns / cycles | +----------+----------------------+-------------------+------------

Ucontext in linux

给你一囗甜甜゛ 提交于 2019-12-04 13:02:10
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? ucontext.h defines functions ( setcontext , getcontext , makecontext , and swapcontext ) and structures ( ucontext_t and mcontext_t ) that allow the programmer to save and restore the program context. Using these functions, a programmer can implement advanced flow control schemes, such as coroutines or lightweight user threads. A good amount of detail (including an example