Bucket sort + Thread

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
    
asked by anonymous 05.11.2015 / 13:42

3 answers

1

The definition of pthread_create is

   int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                      void *(*start_routine) (void *), void *arg);

As you can see from the definition, the function pthread_create expects as a third argument a function with the following signature:

void *f(void *) ;

Your bucketSort function has a signature:

void bucketSort(long *)

Hence the error message:

Error] invalid use of void expression

    
08.11.2015 / 12:01
0

I tried to pass to void, but gave the following error

[Warning] pointer of type 'void' used in arithmetic [-Wpointer-arith] [Error] 'void' is not a pointer-to-object type

    
08.11.2015 / 21:50
0

In addition to changing the subscription you need to cast on the variable before doing operation with it.

void funcao( void * long_var )  {
    long plus1 = *(long*)long_var + 1;
}
    
18.11.2015 / 13:55