Created
March 15, 2014 08:34
-
-
Save jonathanmarvens/9563510 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
void * print_message(void *); | |
int main(void) { | |
pthread_t thread_1; | |
pthread_t thread_2; | |
const char * message_1 = "Thread 1"; | |
const char * message_2 = "Thread 2"; | |
int thread_1_ret; | |
int thread_2_ret; | |
thread_1_ret = pthread_create( | |
&thread_1, | |
NULL, | |
print_message, | |
(void *) message_1 | |
); | |
thread_2_ret = pthread_create( | |
&thread_2, | |
NULL, | |
print_message, | |
(void *) message_2 | |
); | |
pthread_join(thread_1, NULL); | |
pthread_join(thread_2, NULL); | |
printf("Thread 1 returns: %d\n", thread_1_ret); | |
printf("Thread 2 returns: %d\n", thread_2_ret); | |
return 0; | |
} | |
void * print_message(void * param) { | |
char * message; | |
message = (char *) param; | |
printf("%s \n", message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment