#include #include #include #include #include #include int *a_location; char *string_location; void *thread_function(void* p){ printf("Thread 1 CPU: %u\n", sched_getcpu()); int a = 47; a_location = &a; sleep(2); printf("A is now %d\n", a); printf("Triva fact: %s\n", string_location); free(string_location); printf("Thread 1 CPU: %u\n", sched_getcpu()); } void *other_thread_function(void* p){ printf("Thread 2 CPU: %u\n", sched_getcpu()); string_location = malloc(128); strcpy(string_location, "A moose was eaten by a shark"); sleep(1); printf("A has the value %d\n", *a_location); *a_location = 64; printf("Thread 2 CPU: %u\n", sched_getcpu()); } int main(){ printf("Main CPU: %u\n", sched_getcpu()); pthread_t thread_handle, thread_handle2; int array[10]; pthread_create(&thread_handle, 0, thread_function, 0); pthread_create(&thread_handle2, 0, other_thread_function, 0); pthread_join(thread_handle, 0); // Wait for the thread to finish pthread_join(thread_handle2, 0); // Wait for the thread to finish printf("Main CPU: %u\n", sched_getcpu()); return 0; }