I'm working on a multi-threading project and I need to make a copy of a thread's stack at some point in code (I need a pointer to that). because I'm going to need that pointer after this thread is exited (and it's stack is freed).
It would also do the job if I could somehow tell pthread_exit()
not to free the stack of thread!
PS: The reason behind this is that I want to use setcontext(ucontext_t*)
later when this thread is actually dead.
As was mentioned, this may be a case of the XY problem. However, the solution is to use a
pthread_mutex_t
in each thread.The function creating the thread would create the
pthread_mutext_t
and pass it to the thread.The thread function would be as follows...
If you need to do this asynchronously, you can register a signal handler for
SIGUSR1
andSIGUSR2
and usepause
to unschedule the thread.Then use
pthread_kill
to raise the signal to the thread...