Exception handling using longjmp()
Posted: Thu Feb 21, 2019 5:21 pm
Hello to everyone,
Today I was doing some experiments trying to simulate the exception construct available in many languages but not in C.
I found out that we can achieve it using setjmp() and longjmp(). Everything works in a single thread environment but not when using multiple threads.
I am thinking if it is possible to make a data structure in which I can store the thread pointer when setjmp() is called and when the exception occurs (in another thread) I change the scheduler using chSchWakeupS() and then calling longjmp().
In this way setjmp() and longjmp() should be called together in the same thread context.
Did anyone have to face this problem?
Thank you in advance for any tips.
Today I was doing some experiments trying to simulate the exception construct available in many languages but not in C.
I found out that we can achieve it using setjmp() and longjmp(). Everything works in a single thread environment but not when using multiple threads.
I am thinking if it is possible to make a data structure in which I can store the thread pointer when setjmp() is called and when the exception occurs (in another thread) I change the scheduler using chSchWakeupS() and then calling longjmp().
In this way setjmp() and longjmp() should be called together in the same thread context.
Did anyone have to face this problem?
Thank you in advance for any tips.