-
March 13th, 2009, 09:37 AM
#1
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?
Last edited by coderodde; March 13th, 2009 at 10:50 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|