I'm trying to create a function that will create threads and use them for mergeSort.

So far i have this:

this is for combining the sorted arrays.

```
void merge(int *arr, int min,int mid,int max)
{
int *tmp = malloc((max-min+1)*sizeof(int));
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j<=mid && m<=max ; i++)
{
if(arr[j]<=arr[m])
{
tmp[i-min]=arr[j];
j++;
}
else
{
tmp[i-min]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k<=max; k++)
{
tmp[i-min]=arr[k];
i++;
}
}
else
{
for(k=j; k<=mid; k++)
{
tmp[i-min]=arr[k];
i++;
}
}
for(k=min; k<=max; k++)
arr[k]=tmp[k-min];
free(tmp);
}
```

```
void mergeSort(int *array, int min, int max, void(*submergeSort)(int *, int, int, int, int) ){
int mid;
if(min < max){
mid=(min+max)/2;
submergeSort(array, min, mid, mid+1, max);
merge(array, min, mid, max);
}
}
```

and this is my function for creating threads:

```
void submergeSortThread(int* array, int min1, int max1, int min2, int max2){
pthread_t t1,t2;
pthread_create(&t1, NULL, mergeSort,(void*)array,min1,max1);
pthread_create(&t2, NULL, mergeSort,(void*)array,min2,max2);
}
```

and i'm stuck here. I don't know if it's even the correct way to create threads like this?

Thank u for the help