// basic C11 threads example - Educational Use Only
// (C)2021 by Pegasus Epsilon <pegasus@pimpninjas.org>
//
// $ cc threads.c -lpthread -o threads
//
#include <threads.h> /* thrd_* */
#ifdef __STDC_NO_THREADS__
#error no threads
#endif
#include <stdio.h> /* printf() */
#include <stdlib.h> /* EXIT_SUCCESS */
int hello (void *arg) {
printf("Hello, World! This is thread ID #%lu!\n", *(long *)arg);
thrd_exit(EXIT_SUCCESS);
}
int main (void) {
thrd_t thread;
for (long i = 0; i < 20; i++)
thrd_create(&thread, &hello, &i);
thrd_join(thread, NULL);
return 0;
}