NO

Author Topic: Error when executing setjmp with the thread_local variable  (Read 1510 times)

Offline Prokrust

  • Member
  • *
  • Posts: 10
Error when executing setjmp with the thread_local variable
« 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;
}

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Error when executing setjmp with the thread_local variable
« Reply #1 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...
/Pelle

Offline Prokrust

  • Member
  • *
  • Posts: 10
Re: Error when executing setjmp with the thread_local variable
« Reply #2 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
« Last Edit: February 09, 2021, 02:14:27 PM by Prokrust »

Offline Prokrust

  • Member
  • *
  • Posts: 10
Re: Error when executing setjmp with the thread_local variable
« Reply #3 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.