31 lines
642 B
C
31 lines
642 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <pthread.h>
|
|
#include <assert.h>
|
|
|
|
#define NUM_THREADS 16
|
|
|
|
void *thread(void *thread_id) {
|
|
int id = *((int *) thread_id);
|
|
printf("Hello from thread %d\n", id);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int main() {
|
|
pthread_t threads[NUM_THREADS];
|
|
int tabid[NUM_THREADS];
|
|
for (int i = 0; i < NUM_THREADS; i++){
|
|
tabid[i] = i+1;
|
|
}
|
|
for (int i = 0; i < NUM_THREADS; i++){
|
|
assert( pthread_create(&threads[i], NULL, thread, &tabid[i]) == 0);
|
|
}
|
|
|
|
for (int i = 0; i < NUM_THREADS; i++){
|
|
assert( pthread_join(threads[i], NULL) == 0);
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|