I'm relatively new to programming so pardon the messy code. I am trying to get into multithreading with different sorting methods and am starting out with a simple bubblesort. I am getting an error with the pthread_create function call. I have tried several slight variations to my syntax, but I am not really sure what my mistake is. Any help would be much appreciated. (Also any tips on the rest of my code if you notice something.)
~~Only relevant code included
#include <iostream>
#include <pthread.h>
#include <cmath>
using namespace std;
//Bubblesort Method
void * bubbleSort(int arr[], int size) {
int i, j = 1;
while (j != 0) {
j = 0;
i = 0;
while (i < size) {
if (arr[i] > arr[i+1]) {
swap(arr[i], arr[i+1]); //Swap function defined elsewhere in code
j++;
}
i++;
}
}
}
int main {
//Define pthreads
pthread_t tid1, tid2, tid3, tid4;
pthread_t *pthreads[] = {&tid1, &tid2, &tid3, &tid4};
//Fill smaller arrays
int smallArraySize = div / 4;
int *first = (int *) malloc(smallArraySize * sizeof(int));
int *second = (int *) malloc(smallArraySize * sizeof(int));
int *third = (int *) malloc(smallArraySize * sizeof(int));
int *fourth = (int *) malloc(smallArraySize * sizeof(int));
for (int k = 0; k < smallArraySize; k++){
first[k] = arr[k];
}
for (int k = 0; k < smallArraySize; k++){
second[k] = arr[k+smallArraySize];
}
for (int k = 0; k < smallArraySize; k++){
third[k] = arr[k+2*smallArraySize];
}
for (int k = 0; k < smallArraySize; k++){
fourth[k] = arr[k+3*smallArraySize];
}
int smallArray[] = {*first, *second, *third, *fourth};
for (int j = 0; j < div; j++) {
pthread_create(pthreads[j], NULL,* bubbleSort, (smallArray[j],smallArraySize));
}
return 0;
}