#include <threads.h>
typedef struct {
int a;
int b;
int result;
} AddTask;
//a thread function takes void * and returns int
int add(void *arg) {
AddTask *task = arg;
task->result = task->a + task->b;
return 0;
}
AddTask task = {3, 5, 0};
thrd_t thread;
if (thrd_create(&thread, add, &task) != thrd_success) {
exit(EXIT_FAILURE);
}
//the main thread goes on while add runs aside
printf("main thread\n");
//the end of main ends the program with all its threads,
//so main waits for the thread before the end
thrd_join(thread, nullptr);
//task.result is 8
printf("task.result is %d\n", task.result);