Questions tagged [ucontext]

The header defines mcontext_t and the associated functions getcontet, setcontext, swapcontext etc. in POSIX. Often used for implementing co-routines.

64 questions
0
votes
0 answers

How to clone a ucontext

I wonder how to clone a ucontext. Note: this is different from getcontext and swapcontext, because I would like to have a fork(2)-like behaviour. Thanks in advance. I've tried double swapping to duplicate user context, but indeed the underlying…
gyrojeff
  • 23
  • 5
0
votes
1 answer

Get return value from ucontext as it terminates

I am implementing a user-level thread lib using ucontext_t. I am linking threads to the scheduler thread via uc_link, however, we need to get the return value on some occasions. I don't know how to get the return value as the contexts are…
beans
  • 31
  • 5
0
votes
0 answers

a thread switching problem about using ucontext.h in a user-level thread implementation

void Mythread::threadSchedule(int n) { if(threadMap_.size() > 1) { int lastId = current_; if(current_ != (--threadMap_.end())->first) { auto it = threadMap_.find(current_); current_ =…
Deateg
  • 1
  • 1
0
votes
1 answer

Exit thread with return

I have a small problem, and I hope finding someone who can help. I am trying to develop a thread library in c using ucontext, and i have developped the basic functions for that. so now my problem is that I want to consider the case when the user…
Ahmed
  • 15
  • 5
0
votes
2 answers

How can I mask the warning from makecontext if the function passed in has parameters?

When using the function, makecontext, from in C, it takes the arguments (ucontext_t* context, void (*someFunction)(void), int numberOfArguments, ...). The numberOfArguments is to pass in arguments into someFunction, but when passing…
Steve
  • 88
  • 8
0
votes
1 answer

Implementing a scheduler for a thread library

I am implementing a thread library in C using makecontext(), getcontext() and swapcontext(). I need to implement a scheduler which is invoked every 5 ms in order to switch contexts with another thread (round robin). How could I implement this timer…
0
votes
1 answer

Why is makecontext not calling my function?

My program contains the line: makecontext( &threadList[ numThreads ].context, (void (*)(void)) &threadStart, 1, 5); Where threadStart() is defined as: static void threadStart(int x){ printf("Yes! Yes! %d\n", x); } I thought this…
Aperson123
  • 129
  • 6
0
votes
1 answer

makecontext producing void value?

My issue concerns this line: int f = makecontext( &threadList[ numThreads ].context My program compiles without error without the assignment operation, but does not work at all. The line appears to do nothing. When I add "int f =" the compiler…
Aperson123
  • 129
  • 6
0
votes
1 answer

How to do multithreading with getcontext() and setcontext()?

If I understand: multi-threading permits to have multiple threads of execution. So during a thread do something, another thread do something else without waiting the other thread. But when I use getcontext() and setcontext(), I have the impression…
Progear
  • 157
  • 8
0
votes
0 answers

makecontext not enough storage for stack

I try to make a header file in C that virtualizes all function calls from ucontext.h library. Everything is working fine except for function makecontext() when I try to call my_makecontext() I get this message: not enough storage for stack:…
mixos
  • 1
  • 1
0
votes
1 answer

Context switching executes same statement twice

I am trying to learn how context switching works and how to make your process switch context after receiving a particular signal. Here is my…
harrythomas
  • 1,407
  • 1
  • 13
  • 17
0
votes
1 answer

Switching between the execution of two function contexts

I am trying to write a program where I have defined two functions and one prints odd numbers while the other prints even numbers. The program executes a function for a certain amount of time and when it receives an alarm signal, it starts executing…
Somebody
  • 165
  • 5
0
votes
1 answer

Seg-fault when trying to swapcontext() into a struct member that is stored in a queue

I've defined a struct called thread with a member called ucontext* tctx. In a function called create_thread(), I create a thread object on the heap and define each one of its members (including the members of the ucontext object). I then add the…
MTV
  • 91
  • 9
0
votes
0 answers

clang bug on pthread with ucontext on mac

I am using ucontext along with pthread. The below program works OK on Linux, but has failed assertion on Mac. The problem seems that thread local variables are not correctly accessed after resuming the context from another thread. The program…
Albert Netymk
  • 1,102
  • 8
  • 24
0
votes
3 answers

warning: ‘noreturn’ function does return

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:…
Breno Santos
  • 174
  • 1
  • 3
  • 12