-1

the task is as follows:

Write a program that takes as parameters a set of data file names (an arbitrary number) and runs all files for parallel processing (using threads). As a processing, use the sorting method (quickSort).

I ran this program through vmbox on the QNX operating system.It has compiled but does nothing.I have a text file with numbers in my project folder and nothing happens to them.or there should be several of them..(i mean files)And one more thing. I get one warning when compiling. After this sign }, which "closes" the void *FileToArray The warning is as follows: control reaches end of non-void function.How to fix it?

I did it on the basis of methodological guidelines.But maybe I missed something. And I would be grateful if you could tell me what I'm doing wrong.

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <sys/syspage.h>


void quickSort (int *b,int left, int right){
    int sort;
    int Dleft = left;
    int Dright = right;
    sort = b[left];
    printf ("%d",pthread_self());
    while(left<right){
        while((b[right]>=sort)&&(left<right))
        right--;
        if (left!=right){
            b[left]=b[right];
            left++;
        }
        while((b[left]<=sort)&&(left<right))
        left++;
        if(left!=right)
        {
            b[right]=b[left];
            right --;
        }
    }
    b[left]=sort;
    sort=left;
    left=Dleft;
    right=Dright;
    if(left<sort)
    quickSort(b,left,sort-1);
    if(right>sort)
    quickSort(b,sort+1,right);
    
}
void *FileToArray(void *name){
    int i =0,j =0;
    int *a=(int*)malloc(sizeof(int)*2);
    FILE *f=fopen(name,"r");
    printf("start - %p\n",name);
    while (feof(f)==0){
        fscanf(f, "%d",&a[i]);
        i++;
        a=(int*)realloc(a,sizeof(int)*i+1);
    }
    fclose(f);
    quickSort(a,0,i-2);
    f=fopen(name,"w");
    for (j=0;j<i-1;j++){
        fprintf(f, "%d\n",a[j]);
    }
    free(a);
    fclose(f);
    printf("finish - %p\n",name);
}
int num_lines_per_cpu;
int num_cpus;
int main(int argc, char** argv) {
    int j;
    pthread_t *thread_ids;
    num_cpus = syspage_ptr->num_cpu;
    thread_ids=malloc(sizeof(pthread_t)*num_cpus);
    num_lines_per_cpu=argc%num_cpus;
    for(j=1;j<argc;j++){
        pthread_create (&thread_ids[j-1],NULL,FileToArray,argv[j]);
    }
    for(j=0;j<argc-1;j++){
        pthread_join(thread_ids[j],NULL);
    }
    return EXIT_SUCCESS;
}

enter image description here

enter image description here

  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/238202/discussion-on-question-by-idk-how--creating-threads). – Samuel Liew Oct 16 '21 at 06:06

1 Answers1

0

The warning is as follows: control reaches end of non-void function.How to fix it?

And it is exactly as it says, you're returning nothing from your function but the return type is void*.

Nowhere in that function you're returning a pointer, unless I missed it.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253