Created
November 3, 2019 06:53
-
-
Save surinoel/425c9df46a437fc70e007b9722f2d8a5 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <pthread.h> | |
void *print1(void *arg) { | |
char *msg = arg; | |
printf("msg : %s\n", msg); | |
return (void *)(100); | |
} | |
void *print2(void *arg) { | |
char *msg = arg; | |
printf("msg : %s\n", msg); | |
return (void *)(200); | |
} | |
int main(int argc, char **argv) { | |
pthread_t id[2]; | |
int ret, status; | |
/* | |
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, | |
void *(*start_routine) (void *), void *arg); | |
*/ | |
char msg1[] = "hello"; | |
char msg2[] = "world"; | |
ret = pthread_create(&id[0], NULL, print1, msg1); | |
if(ret != 0) { | |
printf("pthread_create ERROR\n"); | |
return -1; | |
} | |
ret = pthread_create(&id[1], NULL, print2, msg2); | |
if(ret != 0) { | |
printf("pthread_create ERROR\n"); | |
return -1; | |
} | |
ret = pthread_join(id[0], (void **)&status); | |
if(ret != 0) { | |
printf("pthread_join ERROR\n"); | |
return -1; | |
} | |
else { | |
printf("ret value : %d\n", status); | |
} | |
ret = pthread_join(id[1], (void **)&status); | |
if(ret != 0) { | |
printf("pthread_join ERROR\n"); | |
return -1; | |
} | |
else { | |
printf("ret value : %d\n", status); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment