Hi,
Is it safe to use longjmp and setjmp in C++ on linux/gcc with regards to the following?
Exception handling (I'm not implementing exception handling using longjmp/setjmp. I want to know what side effects longjmp/setjmp will have on standard exception handling)
*this pointer
Signals
Smart pointers (boost's shared and intrusive point...
I am writing a user space thread library. I have a struct that manages each thread. My threads are very simple, they take a function ptr and its arguments, and just run that function one time.
Each thread has a jmp_buf and I use setjmp and longjmp to switch between threads. One thing I cant figure out is how to tell when this function i...
Im trying to modify a jmp_buf so it executes a function (after i setjmp and longjmp back in).
I have a struct called t that stores information about each thread.
start_routine is a function pointer that should be executed.
/* this is inside an init() function setting stuff up */
void init(void *(*start_routine)(void*), void *arg)
{
...
I'm using the following code to try to read an input from user and timeout and exit if more than 5 seconds pass. This is accomplished through a combination of setjmp/longjmp and the SIGALRM signal.
Here's the code:
#include <stdio.h>
#include <setjmp.h>
#include <unistd.h>
#include <string.h>
#include <sys/signal.h>
jmp_buf buffer;
/...
I am running ubuntu 9.10 (karmic koala), and I took a look at the jmp_buf structure which is simply an array of 12 ints. When I use setjmp, and pass in a jmp_buf structure -- 4 out of 12 entries are saved off. These 4 entries are the stack pointer, frame pointer, program counter and return address. What are the other 8 entries for? Are t...
#include <setjmp.h>
#include <vector>
int main(int argc, char**) {
std::vector<int> foo(argc);
jmp_buf env;
if (setjmp(env)) return 1;
}
Compiling the above code with GCC 4.4.1, g++ test.cc -Wextra -O1, gives this confusing warning:
/usr/include/c++/4.4/bits/stl_vector.h: In function ‘int main(int, char**)’:
/usr/include/c++/4.4...
I want to implement POSIX compliant microthreads in Linux environment. Basic idea is as follows:
Using technique described here, assign new stack space for each fiber.
Using setitimer, create timer that will send signals in constant time interval. Signal handler for this timer will act as a scheduler and switch between fibers.
The pr...
If I place atexit( fn ); on the exit stack, it will get executed when the program exits: returns from main() or via exit().
Can I remove it from the stack?
Why do I want to do this, you ask?
I was experimenting with a simple try-catch mechanism using atexit, setjmp and longjmp. It would be just perfect if I could undo-atexit(fn); - ev...
Hi,
is there a way to implement multitasking using setjmp and longjmp
...
I need to make sure i understand some basic stuff first:
how do i pass function A as a parameter to function B?
how do i call function A from inside B ?
Now for the big whammy:
I'm trying to do something along the lines of this:
jmp_buf buf;
buf.__jmpbuf[JB_PC] = functionA;
longjmp(buf,10);
Meaning that I want to use longjmp in o...
I want to use longjmp to simulate goto instruction.I have an array DS containing elements of struct types (int , float, bool ,char). I want to jump to the place labled "lablex" where x is DS[TOP].int_val. how can I handle this?
sample code :
...
jmp_buf *bfj;
...
stringstream s;s<<"label"<<DS[TOP].int_val;
bfj = (jmp_buf *) s.str();
lo...
I'm tring to define jmp_buf as pointer and using it in nested longjmp(s).as follow:
...
jmp_buf *bfj;
...
and then writing if else:
if( setjmp(*bfj) == 0){
DS[SP-2].int_val=(int)bfj;;
//to store the bfj
}else {}
and somewhere else using the stored bfj to longjmp
bfj = (jmp_buf *)DS[TOP].int_val;
longjmp(*bfj,1);
where DS[TOP]...
I'm working on a library where I'm farming various tasks out to some third-party libraries that do some relatively sketchy or dangerous platform-specific work. (In specific, I'm writing a mathematical function parser that calls JIT-compilers, like LLVM or libjit, to build machine code.) In practice, these third-party libraries have a t...