Skip to content

Instantly share code, notes, and snippets.

@sunny1304
Created January 14, 2014 06:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunny1304/8414134 to your computer and use it in GitHub Desktop.
Save sunny1304/8414134 to your computer and use it in GitHub Desktop.
POSIX Pthread_create example
#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