Search code examples
cmultithreadingserverthreadpoolposix-select

Error "Conversion to non-scalar type requested"


I'm trying to implement a multithread server with a thread pool and using the select, so I have fd_set set declared globally that I pass to the function that the thread pool runs.I get this error

In function ‘threadF’ conversion to non-scalar type requested fd_set set1=(fd_set) s;

and the code is this

pool *createPool(int size){
    /*...*/
    if((err=pthread_create(&id,NULL,&threadF,(void *)&set))!=0){
        fprintf(stderr,"thread\n");
        exit(errno);
    }
    /*...*/
}

void *threadF(void* s){
    fd_set set1=(fd_set) s;
    /*...*/
}

Maybe I'm forgetting something?


Solution

  • Scalar types is the formal name for arithmetic types (regular variables) and pointers. The opposite is aggregate types, which is arrays and structs. The compiler thinks you are making a conversion from scalar s to something else. In plain English: don't convert from a pointer to a struct instance.

    The scalar s is a pointer, but you cast this to a struct type, rather than to a pointer to a struct (which is what you pass to pthread_create). Try:

    fd_set* set1 = (fd_set*)s;