#include #include #include #include #define THREADS 3 typedef struct test_t { int one, two, three, four, threadnum; } test_t; void *printTest(void *test) { test_t *test2; test2 = (test_t *)test; printf("thread: %d\n one: %d\n two: %d\n three: %d\n four: %d\n", test2->threadnum, test2->one, test2->two, test2->three, test2->four); pthread_exit(NULL); } int main(void) { pthread_t threads[THREADS]; test_t data[THREADS]; int i; for (i = 0; i < THREADS; i++) { data[i].threadnum = i; data[i].one = i + 1; data[i].two = i + 2; data[i].three = i + 3; data[i].four = i + 4; pthread_create(&threads[i], NULL, printTest, (void *)&data[i]); } pthread_exit(NULL); return (0); } nelson11@zoidberg:~/code$ a.out thread: 0 one: 1 two: 2 three: 3 four: 4 thread: 1 one: 2 two: 3 three: -1208278976 four: 5 thread: 2 one: 3 two: 4 three: 5 four: 6