1
I’m having the following error in this code:
#define TAM 10000 /*Tamanho do vetor*/
#define NUM 10000 /*base para gerador de numeros aleatorios*/
using std::cout;
using std::cin;
using std::endl;
pthread_t thread[TAM];
void gerarVet(long*);
void bucketSort(long*);
void imprimaVet(long*);
int main(){
long vet[TAM],tinicio,tfim,tempo, i, Troca=0;
long rt1, rt2;
tinicio=time(NULL);
gerarVet(vet);
//imprimaVet(vet);
do {
Troca = 0;
for(i = 0; i < TAM; i+=2)
{
pthread_t t = thread[i];
rt1 = pthread_create(&t, NULL, bucketSort(vet), (void*) &i);
}
for(i = 0; i < TAM; i+=2)
pthread_join(thread[i], NULL);
Troca = 0;
for(i = 1; i < TAM; i+=2)
{
pthread_t t = thread[i];
rt2 = pthread_create(&t, NULL, bucketSort(vet), (void*)&i);
}
for(i = 1; i < TAM; i+=2)
pthread_join(thread[i], NULL);
} while(Troca == 1);
//bucketSort(vet);
imprimaVet(vet);
Error message:
39 79 C: [Error] invalid use of void expression
49 61 C: [Error] invalid use of void expression
I’m not entirely sure if that’s the problem, but you shouldn’t store the thread pointer in the array
thread
after have created it? When you create the thread and get the pointer ont
, you simply ignore it and then use the value ofthread[i]
that does not point to a necessarily correct area... Right? Passing test&thread[i]
in place of&t
, in the call forpthread_create
.– Luiz Vieira
It didn’t work... I tried to make him(i) take on a pointer, but I still have the same problem
– Gustavo G.
Are you passing a pointer to a local variable (i) by reference? This is not recipe for disaster?
– Pablo Almeida