简体   繁体   中英

why can't i return array values to main function?

I am created a main function for thread creation in Linux with a function to read that data . my main code contain initialization of thread as :

main function :

int main(int argc , /*no of aruments*/
            char *argv[])/*store each argument values*/
 {
    pthread_t thid[count];
    create_thread(argv,count,&thid);

 }

and my function as :

int create_thread(char *argv[],int count , pthread_t **thid)
{
     for(index = 1; index <= count; index++)
    {

         status = pthread_create(&thid[index],NULL,file_op,(void*)   mystruct);/*create main threads*/
    }
}

I got error like

function.c:: warning: passing argument 1 of ‘pthread_create’ from incompatible pointer type
 /usr/include/pthread.h: note: expected ‘pthread_t * __restrict__’ but argument is of type ‘pthread_t **

and

main.c: In function ‘main’:
main.c:: warning: passing argument 3 of ‘create_thread’ from    incompatible pointer type
function.c:: note: expected ‘pthread_t **’ but argument is of type ‘pthread_t (*)[(long unsigned int)(count)]’

is there any problem problem on thread code ? how I declare correct syntax ? I want to get all values from function to main array .

Make two changes:

create_thread(argv,count,thid);

and

int create_thread(char *argv[],int count , pthread_t *thid)

That will pass the array to your function and it will pass a pointer to one of the thread IDs to be updated by pthread_create.

pthread_create function's first parameter requires pthread_t * . You are passing wrong type of argument.

Check this out: pthread_create

Also create_thread() is writing beyond the end of the thid array. The loop should be

for (index = 0; index < count; index++)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM