Sto provando a passare due parametri a un thread in C. Ho creato un array (di dimensione 2) e sto provando a passare quell'array nel thread. È questo l'approccio giusto per passare più parametri in un thread?Come passare più parametri a un thread in C
// parameters of input. These are two random numbers
int track_no = rand()%15; // getting the track number for the thread
int number = rand()%20 + 1; // this represents the work that needs to be done
int *parameters[2];
parameters[0]=track_no;
parameters[1]=number;
// the thread is created here
pthread_t server_thread;
int server_thread_status;
//somehow pass two parameters into the thread
server_thread_status = pthread_create(&server_thread, NULL, disk_access, parameters);
Verificare la normativa si dichiara un array di puntatori a int e l'assegnazione loro con valori int. – Teudimundo
Ho notato quell'avvertimento. Sarebbe legittimo se i parametri non fossero puntatori e semplicemente un array? –
se dichiari che il parametro è un array di int ("int parameter [2];"), puoi passare il parametro come puntatore. È il puntatore al primo int. È quindi possibile accedervi dal thread come una matrice. – Teudimundo