Created
November 3, 2019 06:44
-
-
Save surinoel/edaa249e1d1af87b5dbe285bdbb660ad 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 *print(void *arg) { | |
char *msg = arg; | |
printf("msg : %s\n", msg); | |
return NULL; | |
} | |
int main(int argc, char **argv) { | |
pthread_t id[2]; | |
int ret; | |
/* | |
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, print, msg1); | |
if(ret != 0) { | |
printf("pthread_create ERROR\n"); | |
return -1; | |
} | |
ret = pthread_create(&id[1], NULL, print, msg2); | |
if(ret != 0) { | |
printf("pthread_create ERROR\n"); | |
return -1; | |
} | |
ret = pthread_join(id[0], NULL); | |
if(ret != 0) { | |
printf("pthread_join ERROR\n"); | |
return -1; | |
} | |
ret = pthread_join(id[1], NULL); | |
if(ret != 0) { | |
printf("pthread_join ERROR\n"); | |
return -1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment