how to pass argument to thread in c code example
Example 1: How to pass a struct value to a pthread in c?
struct my_Struct{
int val1, val2;
};
void* my_Func(void *received_struct){
struct my_Struct *struct_ptr = (struct my_Struct*) received_struct;
printf("Value 1: %d | Value 2: % \n", struct_ptr->val1, struct_ptr->val2);
}
struct my_Struct mystruct_1[n];
pthread_create(&thread, NULL, my_Func, &mystruct_1[i]);
Example 2: thread parameters c
We use "pthread_create" to create a thread, thread id is the first
argument, NULL is the second argument(which should be some attribute,
but we may not use it), the third argument is the function, then the
last argument is what we want to pass to the new thread.