how to pass an array to a thread in c?
C
void* my_Func(void *received_arr){
int *arr = (int *)received_arr;
for (int i=0; i<5; i++){
printf("Value %d: %d\n", i+1, arr[i]);
}
//Now use arr[] as you wish
}
//In main:
int values[n];
pthread_create(&thread, NULL, my_Func, (void *)values);
//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){
int *arr = (int *)received_arr;
for (int i=0; i<5; i++){
printf("Value %d: %d\n", i+1, arr[i]);
}
//Now use arr[] 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;
pthread_create(&tid, NULL, my_Func, (void *)values);
pthread_join(tid, NULL);
}
//To run: gcc [C FILE].c -lpthread -lrt
//./a.out
//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=9192void* 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
Also in C:
- Title
- char to int c
- Category
- C
- Title
- where is my vimrc
- Category
- C
- Title
- entete c/c++
- Category
- C
- Title
- delete docker image repository none
- Category
- C
- Title
- msdos
- Category
- C
- Title
- c allocate array
- Category
- C
- Title
- es vocal
- Category
- C
- Title
- conda windows 10 from pip._internal.cli.main import main ModuleNotFoundError
- Category
- C
- Title
- get current used proxy windows 7
- Category
- C
- Title
- command line coursera
- Category
- C
- Title
- fgets c
- Category
- C
- Title
- variadic function in c
- Category
- C
- Title
- array length c
- Category
- C
- Title
- measure time in c
- Category
- C
- Title
- Couldn't create temporary file to work with
- Category
- C
- Title
- confirm sweet alert
- Category
- C
- Title
- compare two chars c
- Category
- C
- Title
- objective c swizzle method
- Category
- C
- Title
- print variable c
- Category
- C
- Title
- sbatch array set max jobs at once
- Category
- C
- Title
- how to get user input in c
- Category
- C
- Title
- mangoosejs
- Category
- C
- Title
- change a attribute in dataframe
- Category
- C
- Title
- ImportError: No module named 'skimage'
- Category
- C
- Title
- c check if file was created
- Category
- C
- Title
- code: 'EADDRINUSE', [0] errno: 'EADDRINUSE', [0] syscall: 'listen', [0] address: '::', [0] port: 5000
- Category
- C
- Title
- how to feed a char array to function in C
- Category
- C
- Title
- get_session` is not available when using TensorFlow 2.0.
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- c radians
- Category
- C
- Title
- piramide
- Category
- C
- Title
- c defined value sum
- Category
- C
- Title
- FILE*
- Category
- C
- Title
- c print array
- Category
- C
- Title
- code in c skipping over scanf
- Category
- C
- Title
- c matrix sintax
- Category
- C
- Title
- chat c socket tcp geeksforgeeks
- Category
- C
- Title
- select all file from date powershell
- Category
- C
- Title
- PS1 modified lags
- Category
- C
- Title
- division recursiva
- Category
- C
- Title
- bella ciao lyrics
- Category
- C
- Title
- tkinter create_line
- Category
- C
- Title
- xmlns='' was not expected
- Category
- C
- Title
- find gcd iteratively
- Category
- C
- Title
- c how to define a variable
- Category
- C
- Title
- how to change the mapping from jkil to wasd in vim
- Category
- C
- Title
- c value set to zero __memmove_avx_unaligned_erms
- Category
- C
- Title
- arduino knn
- Category
- C
- Title
- -> operator
- Category
- C
- Title
- time now c
- Category
- C
- Title
- print in c
- Category
- C
- Title
- download android ndk r 16
- Category
- C
- Title
- c printf uint32_t
- Category
- C
- Title
- concatenate two strings in c
- Category
- C
- Title
- typedef in c
- Category
- C
- Title
- how to get random numbers in c
- Category
- C
- Title
- hello world
- Category
- C
- Title
- how to convert int in to const char in c
- Category
- C
- Title
- malloc in c
- Category
- C
- Title
- uninstall elgg from hostgtor
- Category
- C
- Title
- Fibonacci program c pthread
- Category
- C
- Title
- pi in c language
- Category
- C
- Title
- printf n characters c
- Category
- C
- Title
- How to pull images from Docker Registry
- Category
- C
- Title
- c check if char is number
- Category
- C
- Title
- error: ‘cout’ was not declared in this scope
- Category
- C
- Title
- what is conio.h
- Category
- C
- Title
- c check if char is an operator
- Category
- C
- Title
- last element from list javascript
- Category
- C
- Title
- can we write a program without main in c
- Category
- C
- Title
- code wars responsable drinker
- Category
- C
- Title
- multiplication in c
- Category
- C
- Title
- how to go to top of file in vim
- Category
- C
- Title
- .\main.c:4:8: error: expected declaration specifiers or '...' before '\x6f726c64'
- Category
- C
- Title
- ‘uint64_t’ was not declared in this scope
- Category
- C
- Title
- es fibo
- Category
- C
- Title
- arduino vscode upload choosing sketch
- Category
- C
- Title
- powershell list big files
- Category
- C
- Title
- what is the meaningof noremap
- Category
- C
- Title
- double return type in c
- Category
- C
- Title
- ModuleNotFoundError: No module named 'easydict'
- Category
- C
- Title
- ModuleNotFoundError: No module named 'tensorboardX'
- Category
- C
- Title
- is c and c++ platform independent
- Category
- C
- Title
- azure storage emulator config
- Category
- C
- Title
- how to pass an array value to a pthread in c
- Category
- C
- Title
- declare character array statically?
- Category
- C
- Title
- how to check where the last char is in a string c
- Category
- C
- Title
- fa fa-facebook
- Category
- C
- Title
- how to represent unsigned char with % c
- Category
- C
- Title
- sue murry
- Category
- C
- Title
- c printf right pad with space
- Category
- C
- Title
- for loop c
- Category
- C
- Title
- 'keras.backend' is not a package
- Category
- C
- Title
- mediawiki upload size
- Category
- C
- Title
- changing tuple values
- Category
- C
- Title
- how to download file in powershell
- Category
- C
- Title
- resto de division recursiva
- Category
- C
- Title
- what is size_t in c
- Category
- C
- Title
- atoi c
- Category
- C
- Title
- strtok
- Category
- C