1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-30 00:00:15 +01:00
libhermit/hermit/usr/examples/thr_hello.c
2015-08-09 20:22:41 +02:00

30 lines
508 B
C

#include <stdio.h>
#include <pthread.h>
#define MAX_THREADS 2
void* thread_func(void* arg)
{
int id = *((int*) arg);
printf("Hello Thread!!! id = %d\n", id);
return 0;
}
int main(int argc, char** argv)
{
pthread_t threads[MAX_THREADS];
int i, param[MAX_THREADS];
for(i=0; i<MAX_THREADS; i++) {
param[i] = i;
pthread_create(threads+i, NULL, thread_func, param+i);
}
/* wait until all threads have terminated */
for(i=0; i<MAX_THREADS; i++)
pthread_join(threads[i], NULL);
return 0;
}