Using threads can introduce extra undefined behavior such as a https://stackoverflow.com/documentation/c/364/undefined-behavior/2622/data-race#t=201706130820201457052. For race-free access to variables that are shared between different threads C11 provides the mtx_lock()
mutex functionality or the (optional) https://stackoverflow.com/documentation/c/4924/atomics#t=201706150835215525448 data-types and associated functions in stdatomic.h
.
#include <threads.h>
#include <stdio.h>
int run(void *arg)
{
printf("Hello world of C11 threads.");
return 0;
}
int main(int argc, const char *argv[])
{
thrd_t thread;
int result;
thrd_create(&thread, run, NULL);
thrd_join(&thread, &result);
printf("Thread return %d at the end\n", result);
}