Error when executing setjmp with the thread_local variable

Started by Prokrust, January 29, 2021, 01:39:05 PM

Previous topic - Next topic

Prokrust

The error occurs when executing the following code:

#include <stdio.h>
#include <threads.h>
#include <setjmp.h>

thread_local jmp_buf _zmem_jmp_;
void qaz(void) {
printf("Qaz\n");
longjmp(_zmem_jmp_,1);
}

int main(int argc, char *argv[]) {
printf("Start\n");
if(!!setjmp(_zmem_jmp_)) { printf("End\n"); return 0; }
qaz();
return 0;
}

Pelle

OK, I havn't done much testing, but it appears to work here...
You need to at least include both the error code/message, and all the compiler options used...
/Pelle

Prokrust

Checked it. Yes, it works with step-by-step debugging and with a separate run outside the environment. But when running from PellesC, an error occurs for some reason:
CRT: unhandled exception (main) -- terminating
*** Process returned 255 ***
PS.
Added a project
PS.PS.
operating system: Windows 7 SP1

Prokrust

Changed the line
thread_local jmp_buf _zmem_jmp_;
to
thread_local jmp_buf _zmem_jmp_= {0};
Now works on any startup.