The new C11 standard provides a support for Multi-Threading.
My Questions are a bit diversified but definitely answerable.
I have had a look at the C11 n1570
Regarding What compilers provide support for the above mentioned features?
. Creation of threads with Pelles C
compiler example:
#include
#include
#define NUM_THREADS 7
static int threadData[NUM_THREADS];
int threadFunction(void * data) {
printf("%d-th thread up\n", *(int*)data);
return 0;
}
int main(void) {
thrd_t threadId[NUM_THREADS];
// init thread data
for (int i=0; i < NUM_THREADS; ++i)
threadData[i] = i;
// start NUM_THREADS amount of threads
for (int i=0; i < NUM_THREADS; ++i) {
if (thrd_create(threadId+i, threadFunction, threadData+i) != thrd_success) {
printf("%d-th thread create error\n", i);
return 0;
}
}
// wait until all threads terminates
for (int i=0; i < NUM_THREADS; ++i)
thrd_join(threadId[i], NULL);
return 0;
}
EDIT: Eliminated thread shared data problem and problem of exiting from main()
earlier than all threads terminates.