CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: HOWTO: implement asynchronic class methods?

  1. #1
    Join Date
    Mar 2009

    Question HOWTO: implement asynchronic class methods?


    I am trying to implement parallel mergesort - algorithm as a method of a container class. The declaration is as follows:

    class SortedArray {
    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 */


    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.

  2. #2
    Join Date
    Feb 2002

    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.


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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)