// Create a thread that infinitely prints a message // The main thread also infinitely prints a message #include #include #include void my_puts(char *s) { for (int i = 0; s[i] != '\0'; i++) { putchar(s[i]); } putchar('\n'); } // This function is called to start thread execution. // It can be given any pointer as an argument. void *run_thread (void *argument) { while (1) { my_puts("Hello from the other thread!!"); } return NULL; } int main (void) { pthread_t thread_id1; int ret = pthread_create (&thread_id1, NULL, run_thread, NULL); if (ret < 0) { fprintf(stderr, "failed to create thread %s", strerror(ret)); return 1; } while(1) { my_puts("Hello from the main!"); } return 0; }