HOWTO: implement asynchronic class methods?
Hi.
I am trying to implement parallel mergesort - algorithm as a method of a container class. The declaration is as follows:
class SortedArray {
public:
void add( int i );
void remove( int i );
...
void sort(){
/* create the second thread calling merge_sort( &arr[len/2], len - len/2 ) *
* and call merge_sort( arr, len/2 ) within the current thread */
}
protected:
int* arr;
int len;
void merge_sort( int* arr, int len );
void merge( int* arr, int lsize, int rsize );
};
So far, I managed to implement such a class and it sorts well in two threads. The problem is:
even on dual-core system the both of threads run synchronically (one waits while another is sorting), hence drawing back any benefit of parallelism, not to mention processing overhead introduced by context switching.
What exactly is to be done in order to go asynchronic (basically thread-unsafe)? Any advice?
Re: HOWTO: implement asynchronic class methods?
Threads are inherently asynchronous. I don't see any code that has any type of thread locking mechanism, so your threads should be running asynchronous already.
Viggy