October 01, 2003
Threading from Managed C++
Threading from Managed C++
Listing 3: A lock block
#using <mscorlib.dll>
using namespace System;
using namespace System::Threading;
class ArrayManip
{
public:
static int TotalValues(int array __gc[])
{
/*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(int values __gc[], int newValue)
{
/*3*/ Monitor::Enter(values);
for (int i = 0; i < values.Length; ++i)
{
values[i] = newValue;
}
Monitor::Exit(values);
}
End of Listing
Previous Page |
1
|
2
|
3
|
4
|
5
|
6
|
7
Next Page