1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00
libhermit/usr/tests/thr_hello.c

35 lines
646 B
C
Raw Permalink Normal View History

2015-08-09 14:24:24 +02:00
#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];
2015-08-17 12:55:02 +02:00
int i, ret, param[MAX_THREADS];
2015-08-09 14:24:24 +02:00
for(i=0; i<MAX_THREADS; i++) {
param[i] = i;
2015-08-17 12:55:02 +02:00
ret = pthread_create(threads+i, NULL, thread_func, param+i);
if (ret) {
2015-08-17 12:55:02 +02:00
printf("Thread creation failed! error = %d\n", ret);
return ret;
} else printf("Create thread %d\n", i);
2015-08-09 14:24:24 +02:00
}
/* wait until all threads have terminated */
for(i=0; i<MAX_THREADS; i++)
pthread_join(threads[i], NULL);
return 0;
}