#include "headers.h" /* error checking left out for legibility */ /* stuff to pass into thread */ typedef struct thread_arg { int* id; char* str; float cost; } arg_t; /* stuff thread returns */ typedef struct thread_val { int id; float cost; } val_t; /* thing thread does */ void *entry_point(void *ptr); int main(int argc, char *argv[]){ pthread_t thread_id; arg_t thread_arg; val_t *thread_val; int local = 7; char str[] = "Me be threaded: %d %f!!\n"; fprintf(stderr, "local is now = %d\n", local); thread_arg.id = &local; thread_arg.str = str; thread_arg.cost = 3.14; pthread_create(&thread_id,NULL,entry_point, &thread_arg); pthread_join(thread_id,(void **)&thread_val); fprintf(stderr, "the thread produced: %d %f\n", thread_val->id, thread_val->cost); fprintf(stderr, "local is now = %d\n", local); exit(EXIT_SUCCESS); } void *entry_point(void *arg){ arg_t input; val_t *output; input = *((arg_t *)arg); output = (val_t *)malloc(sizeof(val_t)); fprintf(stderr, input.str, *input.id, input.cost); (*input.id)++; output->id = *input.id; output->cost = input.cost * (*input.id); pthread_exit(output); }