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);
|
2015-12-30 02:16:24 +01:00
|
|
|
if (ret) {
|
2015-08-17 12:55:02 +02:00
|
|
|
printf("Thread creation failed! error = %d\n", ret);
|
2015-12-30 02:16:24 +01:00
|
|
|
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;
|
|
|
|
}
|