Created
January 14, 2014 06:41
-
-
Save sunny1304/8414134 to your computer and use it in GitHub Desktop.
POSIX Pthread_create example
This file contains 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> | |
typedef struct student{ | |
char *name; | |
int age; | |
}Student; | |
void *show_student(void *student); | |
int main(int argc, char const *argv[]) | |
{ | |
Student student1 = {"Kimi", 10}; | |
Student student2 = {"Raikkonen", 20}; | |
pthread_t thread1; | |
pthread_t thread2; | |
pthread_create(&thread1, NULL, show_student, (void *)&student1 ); | |
pthread_create(&thread2, NULL, show_student, (void *)&student2 ); | |
pthread_exit(NULL); | |
} | |
void *show_student(void *student){ | |
Student *local_student = (Student *) student; | |
printf("%s, ", local_student -> name ); | |
printf("%d\n", local_student -> age ); | |
pthread_exit(NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment