how to pass an array value to a pthread in c
C
void* my_Func(void *received_arr_Val){
int single_val = (int *)received_arr_Val;
printf("Value: %d\n", single_val);
//Now use single_val as you wish
}
//In main:
int values[n];
pthread_create(&thread, NULL, my_Func, values[i]);
//i is the index number of the array value you want to send
//n is the total number of indexes you want (array size)
//Grepper profile: https://www.codegrepper.com/app/profile.php?id=9192//Runnable example
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void* my_Func(void *received_arr_Val){
int single_val = (int *)received_arr_Val;
printf("Value: %d\n", single_val);
//Now use single_val as you wish
}
int main(){
int values[5];
printf("\nEnter 5 numbers:\n");
for (int i=0; i<5; i++){
scanf("%d", &values[i]);
}
pthread_t tid[5];
for(int i=0; i<5; i++){
pthread_create(&(tid[i]), NULL, my_Func, values[i]);
}
for (int i=0; i<5; i++){
pthread_join(tid[i], NULL);
}
}
//To run: $ gcc [C FILE].c -lpthread -lrt
// $ ./a.out
//Grepper profile: https://www.codegrepper.com/app/profile.php?id=9192
Also in C:
- Title
- how to globally initlailize a struct
- Category
- C
- Title
- Switch Mode C Programming
- Category
- C
- Title
- windowns 10 allow ping
- Category
- C
- Title
- factors using recursion
- Category
- C
- Title
- append to list in c
- Category
- C
- Title
- how to remove \n from a string c
- Category
- C
- Title
- convert string to float c
- Category
- C
- Title
- how to do Employing defensive code in the UI to ensure that the current frame is the most top level window
- Category
- C
- Title
- slug urls django
- Category
- C
- Title
- 'keras.backend' is not a package
- Category
- C
- Title
- remove an element from a set
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- multiplicacion recursiva
- Category
- C
- Title
- hostbuilder add environment variables
- Category
- C
- Title
- how to use ? in c
- Category
- C
- Title
- how to go to top of file in vim
- Category
- C
- Title
- program using if statement in c whether numnber is less eqaul to greater than 50
- Category
- C
- Title
- Fibonacci program c pthread
- Category
- C
- Title
- how to put a char into a string c
- Category
- C
- Title
- switch case c
- Category
- C
- Title
- incompatible types when initializing type ‘float’ using type ‘point {aka struct point}’
- Category
- C
- Title
- how to check the size of a file c
- Category
- C
- Title
- how to declare 2 d array using malloc
- Category
- C
- Title
- root in C
- Category
- C
- Title
- 'int' is not a subtype of type 'double' dart
- Category
- C
- Title
- c printf right pad with space
- Category
- C
- Title
- C why is is & nit used in scan f fr string
- Category
- C
- Title
- iterate through map
- Category
- C
- Title
- vbl share price
- Category
- C
- Title
- c check if array is empty
- Category
- C
- Title
- how to find the ith row of pascal's triangle in c
- Category
- C
- Title
- C largest unsigned int
- Category
- C
- Title
- diferencia entre * y & en c
- Category
- C
- Title
- for loop c
- Category
- C
- Title
- what is stdin in c
- Category
- C
- Title
- coin row problem in linear time
- Category
- C
- Title
- c radians
- Category
- C
- Title
- find gcd iteratively
- Category
- C
- Title
- arduino millis()
- Category
- C
- Title
- atoi c
- Category
- C
- Title
- what is size_t in c
- Category
- C
- Title
- c isdigit function
- Category
- C
- Title
- multiplication operator in c
- Category
- C
- Title
- how to put a struct in another struct C
- Category
- C
- Title
- Print the number 0 using write()
- Category
- C
- Title
- css selector for sibling element
- Category
- C
- Title
- matplotlib plot circle marker
- Category
- C
- Title
- write array of char to file in c
- Category
- C
- Title
- how to call the tkinter insert command from another class
- Category
- C
- Title
- how to get random numbers in c
- Category
- C
- Title
- what are the causes of memory leaks in c
- Category
- C
- Title
- select all file from date powershell
- Category
- C
- Title
- how to comment in arduino
- Category
- C
- Title
- boolean function c
- Category
- C
- Title
- how to mutex lock in c
- Category
- C
- Title
- how to print a file c
- Category
- C
- Title
- functions return type in c
- Category
- C
- Title
- atoi
- Category
- C
- Title
- get_session` is not available when using TensorFlow 2.0.
- Category
- C
- Title
- how to open chrome using cmd
- Category
- C
- Title
- c value set to zero __memmove_avx_unaligned_erms
- Category
- C
- Title
- printf("%3d ",XX);
- Category
- C
- Title
- oop244
- Category
- C
- Title
- sue murry
- Category
- C
- Title
- resto de division recursiva
- Category
- C
- Title
- mongodb delete all documents
- Category
- C
- Title
- c program to find the sum of given number
- Category
- C
- Title
- multiplication in c
- Category
- C
- Title
- change a attribute in dataframe
- Category
- C
- Title
- fgets c
- Category
- C
- Title
- accessing elements of 1d array using pointers
- Category
- C
- Title
- fibonacci series using recursion
- Category
- C
- Title
- can we write a program without main in c
- Category
- C
- Title
- powershell search big files
- Category
- C
- Title
- get configuration script window 7
- Category
- C
- Title
- xmlns='' was not expected
- Category
- C
- Title
- how to change the mapping from jkil to wasd in vim
- Category
- C
- Title
- write a binary file c
- Category
- C
- Title
- read files in c
- Category
- C
- Title
- reverse function in c
- Category
- C
- Title
- conda windows 10 from pip._internal.cli.main import main ModuleNotFoundError
- Category
- C
- Title
- hopw to check how many duplicates in an array c
- Category
- C
- Title
- entete c/c++
- Category
- C
- Title
- pointer parameter where to put the asterix in C?
- Category
- C
- Title
- latex font sizes
- Category
- C
- Title
- printf n characters c
- Category
- C
- Title
- what is strikethrough in markdown
- Category
- C
- Title
- print variable c
- Category
- C
- Title
- ‘uint64_t’ was not declared in this scope
- Category
- C
- Title
- mangoosejs
- Category
- C
- Title
- curl post request
- Category
- C
- Title
- confirm sweet alert
- Category
- C
- Title
- array length c
- Category
- C
- Title
- cantidad de digitos recursiva
- Category
- C
- Title
- how to pass an array value to a pthread in c
- Category
- C
- Title
- hello world
- Category
- C
- Title
- múltiplos entre dos numeros en c
- Category
- C
- Title
- infinite loop using while
- Category
- C
- Title
- changing tuple values
- Category
- C
- Title
- typedef vs #define
- Category
- C