Hi, I had to run some functions asynchronously and I found a function called “Thread()”.
I’ve been using it easily with functions that have no inputs like…
void Something(){
}
thread("Something");
But I got a problem when it comes to functions with inputs.
void SomethingWithInput(int input){
}
something like this.
How can I use Thread function correctly in this kind of situation? Or maybe another method that I can run it asynchronously.
I really thank you for your answer. Now I know how to deal with it. But I’m actually using a function with recursive call and I still don’t get it when it comes to this kind of function.
void QuickSort(int left, int right) {
if (left <= right) {
int pivot = Partition(left, right);
QuickSort(left, pivot - 1);
QuickSort(pivot + 1, right);
}
}
int Partition(int left, int right) {
int pivot = arr[left];
int low = left + 1;
int high = right;
while (low <= high) {
while (pivot >= arr[low] && low <= right) {
low++;
}
while (pivot <= arr[high] && high >= (left+1)) {
high--;
}
if (low <= high) {
swap(low, high);
}
}
swap(left, high);
return high;
}
(Quick sort function)
How can I use Thread for a function with recursive calls? Thanks a lot