FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
October 01, 2005

C++/CLI Threading: Part I

(Page 6 of 7)

October, 2005: C++/CLI Threading: Part I

Listing 3

using namespace System;
using namespace System::Threading;

public ref struct ArrayManip
{
  static int TotalValues(array<int>^ array)
  {
/*1*/   int sum = 0;
/*2*/   Monitor::Enter(array);
    {
      for (int i = 0; i < array->Length; ++i)
      {
        sum += array[i];
      }
    }
    Monitor::Exit(array);
    return sum;
  }

  static void SetAllValues(array<int>^ array, int newValue)
  {
/*3*/   Monitor::Enter(array);
    {
      for (int i = 0; i < array->Length; ++i)
      {
        array[i] = newValue;
      }
    }
    Monitor::Exit(array);
  }

  static void CopyArrays(array<int>^ array1, array<int>^ array2)
  {
/*4*/   Monitor::Enter(array1);
    {
/*5*/     Monitor::Enter(array2);
      {
        Array::Copy(array1, array2, 
          array1->Length < array2->Length ? array1->Length
          : array2->Length);
      }
      Monitor::Exit(array2);
    }
    Monitor::Exit(array1);
  }
};

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK