c - pthread_create int instead of void -
i have following code:
for(i = 0 ; < max_thread; i++) {     struct arg_struct args;     args.arg1 = file;     args.arg2 = word;     args.arg3 = repl;     if(pthread_create(&thread_id[i],null,&do_process,&args) != 0)     {         i--;         fprintf(stderr,red "\nerror in creating thread\n" none);     } } for(i = 0 ; < max_thread; i++)     if(pthread_join(thread_id[i],null) != 0)     {         fprintf(stderr,red "\nerror in joining thread\n" none);     }   int do_process(void *arguments) { //code missing }   *how can transform (void *)do_process (int) do_process ?*
that function returns important info , without returns don't know how read replies
i following error: warning: passing arg 3 of `pthread_create' makes pointer integer without cast
the thread function returns pointer. @ minimum, can allocate integer dynamically , return it.
void * do_process (void *arg) {     /* ... */     int *result = malloc(sizeof(int));     *result = the_result_code;     return result; }   then, can recover pointer thread_join() call;
    void *join_result;     if(pthread_join(thread_id[i],&join_result) != 0)     {         fprintf(stderr,red "\nerror in joining thread\n" none);     } else {         int result = *(int *)join_result;         free(join_result);         /* ... */     }      
Comments
Post a Comment