Pelles C forum

Pelles C => Bug reports => Topic started by: Prokrust on January 29, 2021, 01:39:05 PM

Title: Error when executing setjmp with the thread_local variable
Post by: Prokrust on January 29, 2021, 01:39:05 PM
The error occurs when executing the following code:
Code: [Select]
#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;
}
Title: Re: Error when executing setjmp with the thread_local variable
Post by: Pelle on January 29, 2021, 07:34:03 PM
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...
Title: Re: Error when executing setjmp with the thread_local variable
Post by: Prokrust on February 09, 2021, 02:09:49 PM
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
Title: Re: Error when executing setjmp with the thread_local variable
Post by: Prokrust on March 09, 2021, 12:37:32 PM
Changed the line
thread_local jmp_buf _zmem_jmp_;
to
thread_local jmp_buf _zmem_jmp_= {0};
Now works on any startup.