Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 .

like image 653
user39320 Avatar asked Jun 20 '26 05:06

user39320


2 Answers

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.

like image 175
Brad Budlong Avatar answered Jun 22 '26 20:06

Brad Budlong


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

Check this out: pthread_create

like image 31
Unavailable Avatar answered Jun 22 '26 20:06

Unavailable



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!