31 lines
695 B
C
31 lines
695 B
C
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
void *start_thread(void *message)
|
|
{
|
|
printf("%s\n", (const char *)message);
|
|
return message;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
pthread_t thing1, thing2;
|
|
const char *message1 = "Thing 1";
|
|
const char *message2 = "Thing 2";
|
|
|
|
/* Create two threads, each with a different message. */
|
|
pthread_create(&thing1, NULL, start_thread, (void *)message1);
|
|
pthread_create(&thing2, NULL, start_thread, (void *)message2);
|
|
|
|
/*
|
|
* Wait for the threads to exit. If we didn't join here,
|
|
* we'd risk terminating this main thread before the
|
|
* other two threads finished.
|
|
*/
|
|
pthread_join(thing1, NULL);
|
|
pthread_join(thing2, NULL);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|