Created
March 19, 2015 17:47
-
-
Save rajabishek/ca089757899374cc6652 to your computer and use it in GitHub Desktop.
Thread - Structures as Parameters
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<pthread.h> | |
struct parameter_t{ | |
int data1; | |
int data2; | |
}structure; | |
void* pthread_func(void* arg){ | |
struct parameter_t* structure = (struct parameter_t*)arg; | |
printf("Data1: %d, Data2: %d",structure->data1,structure->data2); | |
return NULL; | |
} | |
int main(){ | |
pthread_t tid; | |
struct parameter_t structure = { 1, 2 }; | |
int error = pthread_create(&tid,NULL,pthread_func,(void*)&structure); | |
if(error != 0 ){ | |
printf("Create thread failed! error: %d",error); | |
return -1; | |
} | |
pthread_join(tid,NULL); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment